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
|