DefaultPersistEventListenerpublic class DefaultPersistEventListener extends AbstractSaveEventListener implements org.hibernate.event.PersistEventListenerDefines the default create event listener used by hibernate for creating
transient entities in response to generated create events. |
Fields Summary |
---|
private static final Log | log |
Methods Summary |
---|
protected void | entityIsPersistent(org.hibernate.event.PersistEvent event, java.util.Map createCache)
log.trace("ignoring persistent instance");
final EventSource source = event.getSession();
//TODO: check that entry.getIdentifier().equals(requestedId)
final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
if ( createCache.put(entity, entity)==null ) {
//TODO: merge into one method!
cascadeBeforeSave(source, persister, entity, createCache);
cascadeAfterSave(source, persister, entity, createCache);
}
| protected void | entityIsTransient(org.hibernate.event.PersistEvent event, java.util.Map createCache)Handle the given create event.
log.trace("saving transient instance");
final EventSource source = event.getSession();
final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
if ( createCache.put(entity, entity)==null ) {
saveWithGeneratedId( entity, event.getEntityName(), createCache, source, false );
}
| protected java.lang.Boolean | getAssumedUnsaved()
return Boolean.TRUE;
| protected org.hibernate.engine.CascadingAction | getCascadeAction()
return CascadingAction.PERSIST;
| public void | onPersist(org.hibernate.event.PersistEvent event)Handle the given create event.
onPersist( event, IdentityMap.instantiate(10) );
| public void | onPersist(org.hibernate.event.PersistEvent event, java.util.Map createCache)Handle the given create event.
final SessionImplementor source = event.getSession();
final Object object = event.getObject();
final Object entity;
if (object instanceof HibernateProxy) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
if ( li.getSession()==source ) {
return; //NOTE EARLY EXIT!
}
else {
throw new PersistentObjectException("uninitialized proxy passed to persist()");
}
}
entity = li.getImplementation();
}
else {
entity = object;
}
int entityState = getEntityState(
entity,
event.getEntityName(),
source.getPersistenceContext().getEntry(entity),
source
);
switch (entityState) {
case DETACHED:
throw new PersistentObjectException(
"detached entity passed to persist: " +
getLoggableName( event.getEntityName(), entity )
);
case PERSISTENT:
entityIsPersistent(event, createCache);
break;
case TRANSIENT:
entityIsTransient(event, createCache);
break;
default:
throw new ObjectDeletedException(
"deleted entity passed to persist",
null,
getLoggableName( event.getEntityName(), entity )
);
}
|
|