I'm getting a cast exception when doing a Hibernate query to the DB.
I just can't understand it. The getClass().getName() method returns
the correct type. However, I just can't seem to cast to the appropriate type.
Thanks in advance.
Hibernate version: 3.1.3
Mapping documents: <?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 name="com.test.UserInfo"> <id name="Key" column="primaryKey" type="string" unsaved-value="null"> <generator class="uuid.hex"/> </id> <property name="name"/> <property name="id"/> <list name="docRecipients" cascade="save-update,delete"> <key column="parentId" not-null="true"/> <list-index column="listIndex"/> <one-to-many class="com.test.DocumentRecipient"/> </list> </class> </hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): SessionFactory sessFact = (SessionFactory)ctx.lookup("hibSessionFactory");
sess = sessFact.openSession(); Object obj = sess.createQuery("from UserInfo where name = :userName") .setString("userName","kjc").list().get(0);
logger.info("object isA.." + obj.getClass().getName()); //: Note: The above statement correctly prints out //: com.test.UserInfo UserInfo uInfo = (UserInfo) obj;
Full stack trace of any exception that occurs: 13:57:20,965 ERROR [UIPortal] java.lang.ClassCastException 13:57:20,966 INFO [STDOUT] java.lang.ClassCastException 13:57:20,968 INFO [STDOUT] at com.test.UIPortal.getUser(Unknown Source)
Name and version of the database you are using: MySQL 5.0.1
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|