title: Hibernate Class Cast Exception
body: <p>I am getting a class cast exception with hibernate when trying to cast the result set to the mapping class... I am able to see the data in the result set that is returned...however it comes back as an Object [] and I am able to set the Object [] to the a List...Am I doing my hibernate mappings correctly? I get the correct data back from the query but its not mapping correctly...</p>
  
  <p><em><strong>Mapping</em></strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.ibm.db2.jcc.DB2Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:db2://****&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;*****&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;*****&lt;/property&gt;
          &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;NONE&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.DB2Dialect&lt;/property&gt;
          &lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
          &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;mapping package="db2"/&gt;
          &lt;mapping class="db2.EQP_UT"/&gt;
          &lt;mapping class="db2.EQP_COMP_PRIMARY"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><em><strong>Mapped Class</em></strong></p>
  
  <pre><code>@Entity
  @Table(name = "EQP_UT")
  public class EQP_UT implements Serializable {
  
      @Id
      private String INITIAL;
  
      @Id
      private String NUMBER;
      private Integer AXL_CNT;
      private String EQP_TYP_CD;
      private String EIN;
      private Integer TRUK_CNT;
  
      @OneToOne
      @JoinTable(name = "EQP_COMP_PRIMARY",
          joinColumns = {@JoinColumn(name = "INITIAL"), @JoinColumn(name = "NUMBER")},
           inverseJoinColumns = {
              @JoinColumn(name = "INITIAL"), @JoinColumn(name="NUMBER")
              }  
      )
      public EQP_COMP_PRIMARY eqp_comp;
  
      public EQP_UT(){
          this.INITIAL = "";
          this.NUMBER = " ";
          int a = this.retrieve();
          System.out.println("This is the data is here..." + a);
      }
  
      public String getNumber()
      {
          return NUMBER;
      }
  
      public void setNumber(String num)
      {
          this.NUMBER = num;
      }
  
      public String getInitial()
      {
          return INITIAL;
      }
  
      public void setInitial(String init)
      {
          this.INITIAL = init;
      }
  
      public int retrieve()
      {
          Session session = null;
          Transaction transaction = null;
  
          try{
              session = HibernateUtil.getDB2SessionFactory().getCurrentSession();
              transaction = session.beginTransaction();
  
              String init = "AARE";
              String number = String.format("%010d", 9350);
              Integer num = Integer.parseInt(number);
  
              String queryString = "SELECT A.INITIAL, A.NUMBER, " + 
                      "A.TRUK_CNT, A.EQP_TYP_CD, A.AXL_CNT, " +
                      "B.TRUK_AXL_CNT, A.EIN FROM EQP_UT AS A " +
                      "LEFT JOIN A.eqp_comp AS B " +
                      "WHERE A.INITIAL||A.NUMBER IN (:carList) AND A.INITIAL IN (:initList) AND A.NUMBER IN (:numberList) " + 
                      "AND B.TRUK_AXL_CNT &gt; 0";
  
              Query query = session.createQuery(queryString);
              query.setParameterList("carList", Globals.returnCarList());
              query.setParameterList("initList", Globals.returnCarListCarInits());
              query.setParameterList("numberList", Globals.returnCarListCarNumbers());
  
              @SuppressWarnings("unchecked")
              List obj =  query.list();
  
              System.err.println("CLASS NAME IS " + obj.get(0).getClass().getClass().getName());
  
              Globals.eqpList = obj; //Globals.eqpList is List&lt;EQP_UT&gt;
  
              session.getTransaction().commit(); 
  
              return 10;      
          }
          catch(HibernateException ex)
          {
              ex.printStackTrace();
              transaction.rollback();
  
          }
          catch(Exception ex)
          {
              System.err.println(ex.getMessage());
          }
  
          return -1;  
      }   
  }
  </code></pre>
  
  <p><em><strong>Joined Class</em></strong></p>
  
  <pre><code>@Entity
  @Table(name = "EQP_COMP_PRIMARY")
  public class EQP_COMP_PRIMARY implements Serializable{
  
          private Integer TRUK_AXL_CNT;
  
          @Id
          private String INITIAL;
          @Id
          private String NUMBER;
  }
  </code></pre>
  
  <p><em><strong>Main</em></strong></p>
  
  <pre><code>//tons more code...
  for(int i = 0; i &lt; Globals.eqpList.size(); i++)
  {
       EQP_UT e = Globals.eqpList.get(i); //class cast exception - and Globals.eqpList is List&lt;EQP_UT&gt;
  }
  //tons more code...
  </code></pre>