Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi, I am trying to map a list of objects(known order) in hibernate using the list collection mapping. In my example I have a bi-directional reference on a Parent and a Child. I have set the inverse='true" property so that I don't get a constraint violation because the parentFK key in the Child table is NOT NULL. However the ordering column doesn't get populated by values. If I remove the inverse="true" property then it gets popualted but I get constraint violation errors in hibernate.
Any help would be appreciated if you have encountered this problem before and managed to find a solution.
Thanks!
Hibernate version:
2.1.7
Mapping documents:
Parent Mapping
<hibernate-mapping>
<class name="persistencebeans.Parent" lazy="true">
<id name="id" type="int" unsaved-value="null">
<column name="id"/>
<generator class="hilo"/>
</id>
<property name="name"/>
<property name="field1"/>
<!-- Parent has a collection of Child. Modelled as a 1:M association. -->
<list name="children" inverse="true" cascade="all" lazy="true">
<key column="parentFK"/>
<index column="ordering"/>
<one-to-many class="persistencebeans.Child"/>
</list>
</class>
</hibernate-mapping>
Child Mapping:
<hibernate-mapping>
<class name="persistencebeans.Child" table="Child">
<id name="id" type="int" unsaved-value="null">
<column name="id"/>
<generator class="hilo"/>
</id>
<property name="name"/>
<!-- Parent and Child have a 1:M relationship -->
<many-to-one
name="Parent"
class="persistencebeans.Parent"
column="parentFK">
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
public void persist(Object object) throws HibernateException{
Session session = factory.openSession();
Transaction transaction = session.beginTransaction();
session.saveOrUpdate(object);
transaction.commit();
session.close();
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: