Hibernate version:
2.1.6
Name and version of the database you are using:
PostgreSQL 7.4.3
First off - Thanks for a great book. I had worked through another smaller book on Hibernate which was very good for getting up and running quickly, but almost led me to rejecting Hibernate for my application when I saw the sql the examples generated. I'm so glad HIA became available - it's been a real eye opener to the power of Hibernate.
Now to my question. I am trying to understand any drawbacks of using "assigned" identifiers - and want to be sure that I am not missing something.
This note in the Hibernate Reference document worried me at first -
Quote:
5.1.4.5. Assigned Identifiers
Due to its inherent nature, entities that use this generator cannot be saved via the Session's saveOrUpdate() method. Instead you have to explicitly specify to Hibernate if the object should be saved or updated by calling either the save() or update() method of the Session.
In HIA in section 3.4.3 at the top of page 92 - regarding assigned identifiers:
Quote:
This strategy has some serious disadvantages when you're working with detached objects and transitive persistence..<snip/> Don't use assigned identifiers if you can avoid them.
OK, now I'm even more worried about using them.
In HIA in section 4.3.4
Quote:
Hibernate will assume that an instance is an unsaved transient if:
The identifier property (if it exists) is null.
The version property (if it exists) is null.
<snip.>
Aha, that sounds better!
Again in HIA in section 8.3.1 there is a discussion on mapping a table with a natural key. This indicates that by using a version property in classes with assigned keys, that saveOrUpdate() and cascades will work correctly.
So, if I make sure that all my classes which will use assigned identifiers also have a version property, does that resolve all issues in using them as detached objects and using transitive persistence? Are there any other downsides/limitations/catches to using assigned ids in Hibernate?
Thanks,
Grainne.