]
Steve Ebersole closed HHH-1047.
-------------------------------
Closing stale resolved issues
replicate() does not handle cascade correctly
---------------------------------------------
Key: HHH-1047
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1047
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.1 rc 1
Environment: 3.1b3, postgres 8
Reporter: snorbii
Hello,
I'm working with sequence-based identifiers, connected to a long property.
My workflow:
- I have an already saved object A.
- A is disconnected for editing by the UI layer.
- After editing is ready I call replicate() (with replication mode "latest") to
synchronize with the database.
My problem is that during editing a new, unsaved object B is added to a many-to-one
association of A. This many-to-one association has CascadeType.ALL.
- When replicate() is executed, it correctly cascades the replication.
- But in DefaultReplicateEventListener.onReplicate() I found the following code:
// get the id from the object
/*if ( persister.isUnsaved(entity, source) ) {
throw new TransientObjectException("transient instance passed to
replicate()");
}*/
Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
if (id==null) {
throw new TransientObjectException("instance with null id passed to
replicate()");
}
persister.getIdentifier() returns 0 because object B is unsaved.
This means that Hibernate does not realize that it is an unsaved object.
So it generates an SQL INSERT for inserting it as a new object, but without generating
an ID for it.
The result is that object B is inserted to the database with ID=0 instead of an ID got
from the sequence.
If object A has two such associations then two rows are inserted with ID=0 which causes
constraint violation.
I think that it would be more correct if replication would save the associated unsaved
object B with a normally generated ID if it is unsaved.
(Am I right that CASCADED replication should save transient instances instead of throwing
an exception?)
BR,
Norbi
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: