are you sure you don't already have a child with the same PK in the database?
No ..There is no child record inserted in to database.
only the parent record is inserted. And strangely an update is being called on the child table with reference to the record which is never inserted !
update child set id=? where id = ? and keyId=?
here id and keyId are the composite PK for the child table.
So what would be great is to set up a minimal test case and post it here
I think I fixed the issue in CVS but I was never able to reproduce it, so I'm not sure.
Thanks for you reply.
I would like to know whether it is possible to persist the parent child entities and expect the results that i am expecting when:
1. child has a composite primary key that has a FK to the parent's table
PK : keyId + id (parent table's primary key)
2. "id" which is a FK and part of child's PK is a sequence number and is generated only when the parent record is inserted in the DB.
3. Both keyId and id are non nullable fields of the child table.
4. when i define bi-directional relation i don't see any exceptions and there is no insert SQL generated for the child table. but when i define only @OneToMany in parent entity i see the parent record insert SQL and update SQL for the child record which may be the update for the parent child relation. and an exception soon after the update is executed.
following is the stack trace..
[SQL] update EVENT_INFO set ID=? where ID=? and keyId=?
[AbstractBatcher] preparing statement
[IntegerType] binding '885218' to parameter: 1
11:53:32,959 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.xo.olb.business.entity.EventInfo
but where is the insert record for the child gone..?
Also Could you please give me the details of the bug you were refering to ..?