-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: index on list doesn't get populated if inverse="true&qu
PostPosted: Wed Feb 08, 2006 7:10 pm 
Newbie

Joined: Mon Dec 20, 2004 9:08 pm
Posts: 9
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:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 9:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If your list is inverse="true" then all elements in the list must be saved first. Inverse="true" means "don't save element, just save reference to it".


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.