title: Problems in JOIN using Hibernate
body: <p>I'm beginner in Hibernate in JAVA and do not know how to solve this problem</p>
  
  <p>I have two tables: Usuario and Certificado, and i want to create a relationship and theirs.</p>
  
  <p>Class Certificado:</p>
  
  <pre><code>@Entity
  @Table(name = "Certificado",
         uniqueConstraints = { @UniqueConstraint( columnNames = { "identifierUnique", "handleUser" } ) } )
  public class Certificado {
      @Id
      @GenericGenerator(name="generator", strategy="increment")
      @GeneratedValue(generator="generator")
      private int handle;
      @Column(length = 255)
      @Column
      private int handleUser;
  
      @ManyToOne
      @JoinColumn(name="handle_user", referencedColumnName="handle")
      private Usuario usuario;
  }
  </code></pre>
  
  <p>Class Usuario:</p>
  
  <pre><code>@Entity
  @Table(name = "Usuario")
  public class Usuario {
      @Id
      @GenericGenerator(name="generator", strategy="increment")
      @GeneratedValue(generator="generator")
      private int handle;
      @Column(length = 255, unique = true)
      private String email;   
      @Column(length = 20)
      private String password;    
      @OneToMany(mappedBy="usuario", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      private Set&lt;Certificado&gt; certificados;
  
          ...
  }
  </code></pre>
  
  <p>When I Execute a SQL function:</p>
  
  <pre><code>public static List&lt;Object[]&gt; loadCertificado30DaysBeforeExperation() throws Exception{      
          Session.begin();
          try {
              try {
                  String select = "SELECT c FROM Certificado c "
                      + "LEFT JOIN c.handleUser AS user";
                  return Session.list(select);
              } catch (Exception e) {
                  throw e;
              }
          } finally {
              Session.commit();
          }
      }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>   java.lang.NullPointerException
  </code></pre>
  
  <p>StackTrace:</p>
  
  <pre><code>java.lang.NullPointerException
      at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:393)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3645)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3431)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3309)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:249)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:184)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:137)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:105)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
      at com.sun.proxy.$Proxy15.createQuery(Unknown Source)
      at br.com.persistence.Session.list(Session.java:96)
      at br.com.utils.ServletUtils.loadCertificado30DaysBeforeExperation(ServletUtils.java:134)
      at br.com.monitoramento.MonitorThread.run(MonitorThread.java:25)
  </code></pre>