|
From: <ja...@he...> - 2006-07-20 20:15:10
|
Hi,
I'm trying to debug/fix Hibernate messages like "org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: "... and I find the default exception logging in AbstractSaveEventListener#performSave not sufficient. I've added some System.err.printlns() with the information I typically need. It would be great if this debug info would make it somehow into the latest SVN.
Rgds
Holger
/**
* Ppepares the save call by checking the session caches for a pre-existing
* entity and performing any lifecycle callbacks.
* @param entity The entity to be saved.
* @param id The id by which to save the entity.
* @param persister The entity's persister instance.
* @param useIdentityColumn Is an identity column in use?
* @param source The session from which the event originated.
* @param requiresImmediateIdAccess does the event context require
* access to the identifier immediately after execution of this method (if
* not, post-insert style id generators may be postponed if we are outside
* a transaction).
* @return The id used to save the entity; may be null depending on the
* type of id generator used and the requiresImmediateIdAccess value
* @throws HibernateException
*/
protected Serializable performSave(
Object entity,
Serializable id,
EntityPersister persister,
boolean useIdentityColumn,
Object anything,
EventSource source,
boolean requiresImmediateIdAccess)
throws HibernateException {
if ( log.isTraceEnabled() ) {
log.trace(
"saving " +
MessageHelper.infoString( persister, id, source.getFactory() )
);
}
EntityKey key;
if ( !useIdentityColumn ) {
key = new EntityKey( id, persister, source.getEntityMode() );
Object old = source.getPersistenceContext().getEntity(key);
if (old != null) {
if ( source.getPersistenceContext().getEntry(old).getStatus() == Status.DELETED ) {
source.forceFlush( source.getPersistenceContext().getEntry(old) );
}
else {
System.err.println("old: " + old);
System.err.println("old.class: " + old.getClass());
System.err.println("entity: " + entity);
System.err.println("entity.class: " + entity.getClass());
System.err.println("id: " + id);
throw new NonUniqueObjectException( id, persister.getEntityName() );
}
}
persister.setIdentifier(entity, id, source.getEntityMode());
}
else {
key = null;
}
if ( invokeSaveLifecycle(entity, persister, source) ) {
return id; //EARLY EXIT
}
return performSaveOrReplicate(
entity,
key,
persister,
useIdentityColumn,
anything,
source,
requiresImmediateIdAccess
);
}
--
Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl
|