How to create a mapping file for an ordered list with Hibernate?

I have a simple Java model where ListHolder contains a list, which in turn can contain ListHolder objects:

public class ListHolder {
    private List<ListHolder> list;
}

My approach to the Hibernate mapping file is as follows:

<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 something wrong in the mapping file? Is there a better way to match lists that work?

Does it make sense to try above with a later version (3.6) of sleep mode?

+3
source share
2 answers

3.6 . javassist CLASSPATH . , --. :

<class name="ListHolder" table="tListHolder">
    <id name="id" column="fid" type="long" />
    <property name="name" column="fname" type="string" length="100" />
    <list name="list" access="field" cascade="all">
         <key column="parentId" />
         <index column="elementIndex"/>
         <many-to-many class="ListHolder"/>
    </list>
</class>
+1

, 3.6 .
javassist.jar CP? .

+1

Source: https://habr.com/ru/post/1776080/


All Articles