I have a simple Java model where a ListHolder holds a List that in turn can hold ListHolder objects:
public class ListHolder {
private List<ListHolder> list;
}
My approach for a Hibernate mapping file looks like this:
<class name="ListHolder" table="tListHolder">
<id column="id" type="int">
<generator class="native"/>
</id>
<list name="list" access="field" cascade="all">
<key column="parent" not-null="true"/>
<index column="elementIndex"/>
<one-to-many class="ListHolder" />
</list>
</class>
When I use the above with Hibernate 3.0, I get the following exception:
Exception in thread "main" org.hibernate.HibernateException:
Unable to instantiate default tuplizer
[org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(
EntityTuplizerFactory.java:110)
Am I doing anything wrong in the mapping file? Is there a better way to map Lists that works?
Does it make sense to try the above with a more recent (3.6) Hibernate version?
Upgrading to 3.6 didn’t change anyhting. Adding javassist to the CLASSPATH brought more helpful error messages. It turned out that another member without a setter was the culprit for the stack trace and that the relationship of the List is actually a many-to-many. The following mapping now works without flaws: