org.hibernate.jpa.event.internal.core.JpaSaveEventListener Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
The core O/RM functionality as provided by Hibernate
The newest version!
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.jpa.event.internal.core;
import java.io.Serializable;
import org.hibernate.event.internal.DefaultSaveEventListener;
import org.hibernate.event.spi.EventSource;
import org.hibernate.jpa.event.spi.jpa.CallbackRegistryConsumer;
import org.hibernate.jpa.event.spi.jpa.CallbackRegistry;
/**
* Overrides the LifeCycle OnSave call to call the PrePersist operation
*
* @author Emmanuel Bernard
*/
public class JpaSaveEventListener extends DefaultSaveEventListener implements CallbackRegistryConsumer {
private CallbackRegistry callbackRegistry;
public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
this.callbackRegistry = callbackRegistry;
}
public JpaSaveEventListener() {
super();
}
public JpaSaveEventListener(CallbackRegistry callbackRegistry) {
super();
this.callbackRegistry = callbackRegistry;
}
@Override
protected Serializable saveWithRequestedId(
Object entity,
Serializable requestedId,
String entityName,
Object anything,
EventSource source) {
callbackRegistry.preCreate( entity );
return super.saveWithRequestedId( entity, requestedId, entityName, anything, source );
}
@Override
protected Serializable saveWithGeneratedId(
Object entity,
String entityName,
Object anything,
EventSource source,
boolean requiresImmediateIdAccess) {
callbackRegistry.preCreate( entity );
return super.saveWithGeneratedId( entity, entityName, anything, source, requiresImmediateIdAccess );
}
}