title: Null objects after database query (using hibernate + smartgwt)
body: <p>This is my first post here, hope I'm doing it right. Let me see how can I explain my problem better, so that you guys can understand it.</p>
  
  <p>[Using: Eclipse, Hibernate, Smartgwt, Java language]</p>
  
  <p>Among others, i have 2 tables in my database (postgreSQL), which are related to one another.</p>
  
  <ul>
  <li><strong>OrganizerUsers</strong> (organizeruser_id [PK], user_id, organizer_id [FK]) - those FKs correlate the table to 2 other unimportant ones.</li>
  <li><strong>Conferences</strong> (conference_id [PK], title, organizeruser_id [FK])</li>
  </ul>
  
  <p>Basically, I need to get all the rows in <strong>Conferences</strong> table. So I'm expecting that after the query, I should get something like a <strong><code>Set&lt;Conferences&gt;</code></strong>, each object in the set containing the info in the table.
  Now, I'm using Hibernate and Smartgwt to build this web app (new to them).
  My mapping files were created automatically in Eclipse. My class files were also created automatically by Hibernate's code generation..thingy.
  Noticed that hibernate does the following thing: Each object within the <code>Set&lt;Conferences&gt;</code> is an <strong>Conferences</strong> object, and it has 3 attributes: </p>
  
  <ul>
  <li>int conference_id</li>
  <li>String title</li>
  <li>an Organizeruser object</li>
  </ul>
  
  <p>That last object is basically the corresponding object taken from the <strong>OrganizerUsers</strong> table (and was picked according to the relationship between <strong>Conferences</strong> and <strong>Organizerusers</strong> tables - a Join operation was made, basically).</p>
  
  <p><strong>THE QUERY:</strong></p>
  
  <pre><code>@SuppressWarnings("unchecked")
      @Override
      public List getConferences() throws IllegalArgumentException {
  
          Session session = HibernateUtil.getSessionFactory().openSession();
          Transaction transaction = null;
          List conferences = null;
          try{
              transaction = session.beginTransaction();
              conferences = session.createQuery("from Conferences").list();
              transaction.commit();
          }catch(Exception e){
              transaction.rollback();
              e.printStackTrace();
          }
          finally {
              session.close();
          }
  
          return conferences;
      }
  </code></pre>
  
  <p>The result is sent via a RPC (in smartgwt), to the client (a webpage). This above query is basically part of a kind of servlet.</p>
  
  <p><strong>THE RESULT:</strong></p>
  
  <p>Client receives the <code>Set&lt;Conferences&gt;</code> conferences object. While outputting data in the webpage, i notice:</p>
  
  <pre><code>Set&lt;Conferences&gt; conferences = [the result from the RPC call];
  conferences.getTitle() //works fine, returns title
  conferences.getConferenceId() //works fine, returns the id
  conferences.getOrganizeruser() //**NULL OBJECT**
  </code></pre>
  
  <p>The <strong>confereces.getOrganizeruser()</strong> should have returned a valid object, taken from the <strong>organizeruser</strong> table. There is a corresponding valid row there.</p>
  
  <p><strong>This is just an example, but everywhere I have a relationship with FKs between two tables, i get this problem.
  Doing an HQL query in that built-in HQL Editor for the same example, seems to give me the right information though o_O [in Hibernate Configurations Tab]. Is it cause of hibernate or.. the SmartGwt RPC call? I doubt it.
  BY THE WAY, I had a similar problem before, with a null set being outputted after the query. I fixed it by fetching it eagerly rather than lazy (default). But I didn't get this to work.</strong></p>
  
  <p><strong>Additional info:</strong>
  Conferences.hbm.xml mapping file [edited - cut out unimportant stuff, and translated the class names which were written in RO]</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="com.test.project.shared.Conferences" table="conferences" schema="public"&gt;
          &lt;id name="conferenceId" type="int"&gt;
              &lt;column name="conference_id" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;many-to-one name="organizerusers" class="com.test.project.shared.Organizerusers" fetch="select"&gt;
              &lt;column name="organizerusers_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;property name="title" type="string"&gt;
              &lt;column name="title" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>Conference.java class</strong> [edited - cut out unimportant stuff, and translated the class names which were written in RO]</p>
  
  <pre><code>@Entity
  @Table(name = "conferences", schema = "public")
  public class Conferinte extends LightEntity  implements java.io.Serializable {
  
      private int conferenceId;
      private Organizerusers organizerusers;
      private String title;
  
      public Conferences() {
      }
  
      public Conferences(int conferenceId, Organizerusers organizerusers{
          this.confereceId = conferenceId;
          this.organizerusers = organizerusers;
      }
  
      public Conferences(int conferenceId, Organizerusers organizerusers, String title){
          this.conferenceId = conferenceId;
          this.organizerusers = organizerusers;
          this.title = title;
      }
  
      @Id
      @Column(name = "conference_id", unique = true, nullable = false)
      public int getConferenceId() {
          return this.conferenceId;
      }
  
      public void setConferenceId(int conferenceId) {
          this.conferenceId = conferenceId;
      }
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "organizeruser_id", nullable = false)
      public Organizerusers getOrganizerusers() {
          return this.organizerusers;
      }
  
      public void setOrganizerusers(
              Organizerusers organizerusers) {
          this.organizerusers = organizerusers;
      }
  
      @Column(name = "title")
      public String getTitle() {
          return this.title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
  }
  </code></pre>