hello Reto, thanks a lot for your help.
I forgot to say that Hibernate deletes both the A and B instances from the data base so all of them become in transient object. In that way when I use Session.save(A) hibernate should insert both A object and B intances collection in the data base, doesn't it?
I'm debugging the execution of my program and I looking throught the hibernate code and in fact the problem is hibernate thinks the b intances collection is detached (but it's transient)
When the execution of my program arrives the following method of the DefaultSaveOrUpdateEventListener class:
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
// use various roles to determine if the instance is
// transient, persistent or detached:
int entityState = getEntityState(
event.getEntity(),
event.getEntityName(),
event.getEntry(),
event.getSession()
);
switch (entityState) {
case DETACHED:
entityIsDetached(event);
return null;
case PERSISTENT:
return entityIsPersistent(event);
default: //TRANSIENT or DELETED
return entityIsTransient(event);
}
}
When the event is the saving of B instances collection the method returns DETACHED and, of course, entityIsDetached is performed and, of course, a SQL UPDATE is performed.
Moreover, from getEntityState method the execution arrives to isUnsaved(Serializable id) method in org.hibernate.engine.Cascades class.
this method is executed with id == Long(24) and value == Long(0) and
returns FALSE. So for hibernate my B objects are not Unsaved (but they are)
public Boolean isUnsaved(Serializable id) {
if ( log.isTraceEnabled() ) log.trace("id unsaved-value: " + value);
return id==null || id.equals(value) ? Boolean.TRUE : Boolean.FALSE;
}
I change my program in order to do not use the same session to delete and save the A object instead of that I'm closing the session in which I perform Session.delete(A) after I'm creating a new session but nothing changes.
I set to true the use_identifer_rollback property in my hibernate configuration file.
but after all, if the B instances have value in the id property, hibernate mark them as DETACHED object. In the other hand the A object is being marked as TRANSIENT object (and it has value in the id property)
Shouldn't Session.delete method set to null the id property?
Should I set to null the id values in all my instances of every persistent collection?
Any idea?
Thanks a lot.
P.D.
I'm using:
hibernate 3.0
Oracle 8.1.7
Sequence id generator algorithm
|