Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3
Mapping documents:
User:
<?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="UserAdapter" table="users">
<id name="id" column="userId">
<generator class="native" />
</id>
<property name="name"/>
<set name="items" table="users_by_items">
<key column="userId"/>
<many-to-many column="userId" class="Item">
</set>
</class>
</hibernate-mapping>
Item:
<?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="ItemAdapter" table="items">
<id name="id" column="itemId">
<generator class="native" />
</id>
<property name="name"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.test.UserAdapter.setItems
...
Caused by: net.sf.cglib.beans.BulkBeanException: org.hibernate.collection.PersistentSet
at com.test.UserAdapte$$BulkBeanByCGLIB$$f5c06d7d.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
... 60 more
Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentSet
Name and version of the database you are using:
MySQL 5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
More info:
User class:
Code:
public class User {
Long id;
String name;
List<Item> items;
}
public class UserAdapter extends User implements IDataAccess{
... more code ....
}
Item class:
Code:
public class Item {
Long id;
String name;
}
public class ItemAdapter extends Item implements IDataAccess{
... more code ....
}
I'm using a class called UserAdapter, that inherits from User and a ItemAdapter that inherits from Item. Both implements an interface to allow objects to be saved. So, Hibernate should return instances of ItemAdapter instead of Item, but I don't think that can cause a ClassCastException.
Any ideas?
PS: I had already set the hibernate.cglib.use_reflection_optimizer property to false in hibernate.cfg.xml.