1 package org.hibernate.event.def; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.HibernateException; 7 import org.hibernate.ObjectDeletedException; 8 import org.hibernate.EntityMode; 9 import org.hibernate.engine.EntityEntry; 10 import org.hibernate.engine.Status; 11 import org.hibernate.event.SaveOrUpdateEvent; 12 import org.hibernate.persister.entity.EntityPersister; 13 14 18 public class DefaultUpdateEventListener extends DefaultSaveOrUpdateEventListener { 19 20 protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) { 21 EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() ); 24 if ( entry!=null ) { 25 if ( entry.getStatus()==Status.DELETED ) { 26 throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() ); 27 } 28 else { 29 return entityIsPersistent(event); 30 } 31 } 32 else { 33 entityIsDetached(event); 34 return null; 35 } 36 } 37 38 42 protected Serializable getUpdateId(Object entity, EntityPersister persister, Serializable requestedId, EntityMode entityMode) 43 throws HibernateException { 44 45 if ( requestedId==null ) { 46 return super.getUpdateId(entity, persister, requestedId, entityMode); 47 } 48 else { 49 persister.setIdentifier(entity, requestedId, entityMode); 50 return requestedId; 51 } 52 } 53 54 } 55 | Popular Tags |