-
1. Re: persisting entities using OneToMany relation
epbernard Feb 21, 2006 6:46 PM (in response to java_tek_2006)are you sure you don't already have a child with the same PK in the database?
-
2. Re: persisting entities using OneToMany relation
java_tek_2006 Feb 21, 2006 7:27 PM (in response to java_tek_2006)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. -
3. Re: persisting entities using OneToMany relation
epbernard Feb 22, 2006 8:43 AM (in response to java_tek_2006)So what would be great is to set up a minimal test case and post it here
http://opensource2.atlassian.com/projects/hibernate/secure/Dashboard.jspa
I think I fixed the issue in CVS but I was never able to reproduce it, so I'm not sure. -
4. Re: persisting entities using OneToMany relation
java_tek_2006 Feb 22, 2006 12:08 PM (in response to java_tek_2006)Hi ,
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
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:107)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:65)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:654)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:927)
.......
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 ..?
Thanks