1 Reply Latest reply on Oct 18, 2005 7:34 PM by nakker

    Jboss 4.0.3 Hibernate 3.0.5 ClassCastException

    nakker

      I recently upgraded my previously functional codebase to use hibernate 3.0.5 and jboss 4.0.3 from hibernate 3.0.1 and jboss 4.0.1sp1. Now when hibernate hits the database with q.uniqueResult() it returns an Object which is of type Client but when i try to cast it to client i get a classCastException. Here are some code snippets... maybe im just an idiot but i dont think so since the code was previously working.

      The hibernate mappiung Client.hbm.xml:

      <?xml version="1.0"?>
      <!DOCTYPE hibernate-mapping PUBLIC
       "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      
      <hibernate-mapping>
       <class table="client" name="com.voltforge.akeso.dbo.client.Client">
       <id name="id" type="java.lang.Integer" column="id">
       <generator class="native"/>
       </id>
       <property name="username" column="username" type="string"/>
      


      The client PoJo
      package com.voltforge.akeso.dbo.client;
      
      import java.sql.Date;
      import java.util.Set;
      import java.util.HashSet;
      
      public class Client{
       private Integer id;
       private String username;
      
       public Integer getId() {
       return this.id;
       }
       public void setId( Integer x ) {
       this.id = x;
       }
      
       public String getUsername() {
       return this.username;
       }
       public void setUsername( String x ) {
       this.username = x;
       }
      }
      


      The logic for getting a client obj
      public static Client getClient(Session s, String username) {
       Client c = null;
       try {
       Query q = s.createQuery("from Client where username=:name");
       q.setString("name", username);
       c = (Client)q.uniqueResult();
      
       } catch (Exception e) {
       log.error(e);
       }
       return c;
       }
      


      The Jboss output is as follows

      12:40:54,000 INFO [STDOUT] Hibernate: select client0_.id as id98_, client0_.facility_id as facility2_98_, client0_.username as username98_, client0_.enc_password as
      enc4_98_, client0_.last_login as last5_98_, client0_.last_password_change as last6_98_, client0_.first_name as first7_98_, client0_.last_name as last8_98_, client0_.p
      hone as phone98_, client0_.email as email98_, client0_.title as title98_, client0_.salutation as salutation98_, client0_.is_blocked as is13_98_, client0_.num_failed_l
      ogins as num14_98_ from client client0_ where client0_.username=?
      12:40:54,171 INFO [ClientLogic] THE OBJECT RETURNED IS com.voltforge.akeso.dbo.client.Client@2e983d
      12:40:54,171 ERROR [ClientLogic] java.lang.ClassCastException: com.voltforge.akeso.dbo.client.Client
      12:40:54,171 INFO [ClientLogic] Authenticating admin
      12:40:54,250 INFO [STDOUT] Hibernate: select client0_.id as id98_, client0_.facility_id as facility2_98_, client0_.username as username98_, client0_.enc_password as
      enc4_98_, client0_.last_login as last5_98_, client0_.last_password_change as last6_98_, client0_.first_name as first7_98_, client0_.last_name as last8_98_, client0_.p
      hone as phone98_, client0_.email as email98_, client0_.title as title98_, client0_.salutation as salutation98_, client0_.is_blocked as is13_98_, client0_.num_failed_l
      ogins as num14_98_ from client client0_ where client0_.username=? and client0_.enc_password=? and client0_.is_blocked=? and client0_.num_failed_logins<?
      12:40:54,250 ERROR [ClientLogic] java.lang.ClassCastException: com.voltforge.akeso.dbo.client.Client
      12:40:54,265 ERROR [SecurityRealm] java.lang.NullPointerException



      Anyone got any great ideas?? Thanks!

        • 1. Re: Jboss 4.0.3 Hibernate 3.0.5 ClassCastException
          nakker

          Figured it out - apparently the older versions of jboss and hibernate didnt care that i had my DBO (Pojo) objects duplicated in my HAR file as well as in my WAR file but the newer versions care. I just took out the duplicate files from the war dir and used the ones in the HAR exclusively.