1 package org.hibernate.event.def; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.Hibernate; 7 import org.hibernate.PersistentObjectException; 8 import org.hibernate.engine.EntityEntry; 9 import org.hibernate.engine.Status; 10 import org.hibernate.event.SaveOrUpdateEvent; 11 import org.hibernate.engine.SessionImplementor; 12 13 17 public class DefaultSaveEventListener extends DefaultSaveOrUpdateEventListener { 18 19 protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) { 20 EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() ); 23 if ( entry!=null && entry.getStatus() != Status.DELETED ) { 24 return entityIsPersistent(event); 25 } 26 else { 27 return entityIsTransient(event); 28 } 29 } 30 31 protected Serializable saveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) { 32 if ( event.getRequestedId() == null ) { 33 return super.saveWithGeneratedOrRequestedId(event); 34 } 35 else { 36 return saveWithRequestedId( 37 event.getEntity(), 38 event.getRequestedId(), 39 event.getEntityName(), 40 null, 41 event.getSession() 42 ); 43 } 44 45 } 46 47 protected boolean reassociateIfUninitializedProxy(Object object, SessionImplementor source) { 48 if ( !Hibernate.isInitialized(object) ) { 49 throw new PersistentObjectException("uninitialized proxy passed to save()"); 50 } 51 else { 52 return false; 53 } 54 } 55 56 57 } 58 | Popular Tags |