Code example for SaveOrUpdateEvent

Methods: getEntity, getSession

0
public class DefaultSaveEventListener extends DefaultSaveOrUpdateEventListener {
 
	protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
		// this implementation is supposed to tolerate incorrect unsaved-value 
		// mappings, for the purpose of backward-compatibility 
		EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
		if ( entry!=null && entry.getStatus() != Status.DELETED ) {
			return entityIsPersistent(event);
		} 
		else { 
			return entityIsTransient(event);
		} 
	} 
	 
	protected Serializable saveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) {
		if ( event.getRequestedId() == null ) {
			return super.saveWithGeneratedOrRequestedId(event);
		} 
		else { 
			return saveWithRequestedId(  
Experience pair programming with AI  Get Codota for Java