I ran into a problem with one class/entity, called Role. I could not retrieve it by property using either query or criteria - the query returns empty set. I can retrieve an object by ID, but the stuff the query returns looks like Role$$EnhancerByCGLIB$$f45a5802 in the debugger (Eclipse), with object properties all nulls. Trying to call any methods on it causes ClassCastExceptions. The rest of the entities work fine and under debugger, look like regular classes - User, Department etc.
The class is completely trivial POJO mapped to a table, with no relationships to other entities.
SQL generated by Hibernate for query or criteria looks correct, and I am able to execute it directly and get expected results.
Any pointers would be much appreciated. I am out of ideas here...
Hibernate version: 3.0.2
Mapping documents: (generated by XDoclet)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!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.project.model3.Role"
table="role"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
not-null="true"
/>
<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="description"
/>
</class>
</hibernate-mapping>
Full stack trace :Code:
[junit] INFO - closing
[junit] INFO - cleaning up connection pool: jdbc:mysql://localhost/almond3
[junit] ------------- ---------------- ---------------
[junit] Testcase: testPopulate(com.project.test.Populate): Caused an ERROR
[junit] null
[junit] java.lang.ClassCastException
[junit] at org.hibernate.type.LongType.set(LongType.java:40)
[junit] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
[junit] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
[junit] at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1078)
[junit] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1140)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:369)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
[junit] at org.hibernate.loader.Loader.loadEntity(Loader.java:1307)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2461)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:392)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:373)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:155)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:117)
[junit] at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:593)
[junit] at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
[junit] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
[junit] at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
[junit] at com.project.model3.Role$$EnhancerByCGLIB$$7707cc54.toString(<generated>)
[junit] at java.lang.String.valueOf(String.java:2131)
[junit] at java.lang.StringBuffer.append(StringBuffer.java:370)
[junit] at com.project.dao.UserOrgRoleDAO.createUserOrgRole(UserOrgRoleDAO.java:24)
[junit] at com.project.test.Populate.associateUsersWithRoles(Populate.java:202)
[junit] at com.project.test.Populate.testPopulate(Populate.java:41)
[junit] Test com.project.test.Populate FAILED
Name and version of the database you are using:The generated SQL (show_sql=true):Code:
[junit] Hibernate: select role0_.id as id0_, role0_.name as name22_0_, role0_.description as descript3_22_0_ from role role0_ where role0_.id=?
Debug level Hibernate log excerpt:
I don't see anything suspicious in Hibernate logs.