-->
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.  [ 1 post ] 
Author Message
 Post subject: Composite-Id and save order
PostPosted: Fri Mar 17, 2006 5:43 pm 
Newbie

Joined: Tue Jan 03, 2006 7:23 pm
Posts: 3
Hibernate version: 3.0.5

Name and version of the database you are using: SQL Server 2000

I have an issue with Hibernate trying to save a composite-id class while one of the key classes is still transient.

I have four legacy tables. Organization is the parent table, and it has two child tables: Users and Licenses. There is a fourth table, LicenseLink. The LicenseLink records have their primary key as the combination of the User primary key and the License primary key. All four of these are represented as objects in my object tree. Licenses and Users both have LicenseLinks as Collections.

The problem is that when I save a transient object tree, I watch the save/update order and Hibernate will save the Licenses, cascading down the LicenseLinks and then when it tries to insert the LicenseLinks, it fails, because the User object is still transient; the foreign key is still ungenerated. I'd like for things to be smart enough such that Hibernate realizes it must save the User object before it can save a LicenseLink that references it.

My mapping for LicenseLink is like this:
<class name="LicenseLink" table="xrLicenseUser">

<composite-id>
<key-many-to-one name="user">
<column name="userId" />
</key-many-to-one>
<key-many-to-one name="license">
<column name="licenseId" />
</key-many-to-one>
</composite-id>
<!-- additional fields -->
</class>

User and License map to respective classes.

The exact exception is this:
object references an unsaved transient instance - save the transient instance before flushing: User


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

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.