Yes it can be done, we just have to figure out how.
IDENTITY generated values cannot be preallocated as they require the insert to occur. So, calling persist(), or merge() of a new object will not assign the Id until you call flush() or commit().
Hemant Thard wrote:Hi,
Here is my observation when I tested with Identity generator class and hibernate.
1. when i call save() on new new Object, i saw an insert query fired and i was able to get primary key value from now persistent object.
2. When i call merge() on new Object, Insert query was fired, but i was getting null for my primary key.
It seems to be that if the object is transient, the way save() and merge behave is completely different.
I don't know the reason for this behavior, but can you try using persist() for new object and post your result.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |