diff --git a/hibernate-core/src/main/java/org/hibernate/CallbackException.java b/hibernate-core/src/main/java/org/hibernate/CallbackException.java
index 5b695b0a38..02f4814be2 100644
--- a/hibernate-core/src/main/java/org/hibernate/CallbackException.java
+++ b/hibernate-core/src/main/java/org/hibernate/CallbackException.java
@@ -5,8 +5,7 @@
package org.hibernate;
/**
- * Intended to be thrown from {@link org.hibernate.classic.Lifecycle}
- * and {@link Interceptor} callbacks.
+ * Intended to be thrown from {@link Interceptor} callbacks.
*
* @implNote This is a legacy exception type from back in the day before
* Hibernate moved to an unchecked exception strategy.
diff --git a/hibernate-core/src/main/java/org/hibernate/Interceptor.java b/hibernate-core/src/main/java/org/hibernate/Interceptor.java
index bca3937c08..e40854b2f3 100644
--- a/hibernate-core/src/main/java/org/hibernate/Interceptor.java
+++ b/hibernate-core/src/main/java/org/hibernate/Interceptor.java
@@ -54,7 +54,6 @@ import org.hibernate.type.Type;
*
* @author Gavin King
*/
-@SuppressWarnings("unused")
public interface Interceptor {
/**
* Called just before an object is initialized. The interceptor may change the {@code state}, which will
diff --git a/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java b/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java
deleted file mode 100644
index 68db4fe33a..0000000000
--- a/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-or-later
- * Copyright Red Hat Inc. and Hibernate Authors
- */
-package org.hibernate.classic;
-
-import org.hibernate.CallbackException;
-import org.hibernate.Session;
-
-import java.io.Serializable;
-
-/**
- * Provides callbacks from the {@code Session} to the persistent object.
- * Persistent classes may implement this interface but they are not
- * required to.
- *
- * - onSave: called just before the object is saved
- *
- onUpdate: called just before an object is updated,
- * ie. when {@code Session.update()} is called
- *
- onDelete: called just before an object is deleted
- * onLoad: called just after an object is loaded
- *
- *
- * {@code onLoad()} may be used to initialize transient properties of the
- * object from its persistent state. It may not be used to load
- * dependent objects since the {@code Session} interface may not be
- * invoked from inside this method.
- *
- * A further intended usage of {@code onLoad()}, {@code onSave()} and
- * {@code onUpdate()} is to store a reference to the {@code Session}
- * for later use.
- *
- * If {@code onSave()}, {@code onUpdate()} or {@code onDelete()} return
- * {@code VETO}, the operation is silently vetoed. If a
- * {@code CallbackException} is thrown, the operation is vetoed and the
- * exception is passed back to the application.
- *
- * Note that {@code onSave()} is called after an identifier is assigned
- * to the object, except when identity column key generation is used.
- *
- * @see CallbackException
- * @see jakarta.persistence.EntityListeners
- * @see jakarta.persistence.PrePersist
- * @see jakarta.persistence.PreRemove
- * @see jakarta.persistence.PreUpdate
- * @see jakarta.persistence.PostLoad
- * @see jakarta.persistence.PostPersist
- * @see jakarta.persistence.PostRemove
- * @see jakarta.persistence.PostUpdate
- *
- * @author Gavin King
- */
-public interface Lifecycle {
-
- /**
- * Return value to veto the action (true)
- */
- boolean VETO = true;
-
- /**
- * Return value to accept the action (false)
- */
- boolean NO_VETO = false;
-
- /**
- * Called when an entity is saved.
- * @param s the session
- * @return true to veto save
- * @throws CallbackException Indicates a problem happened during callback
- */
- default boolean onSave(Session s) throws CallbackException {
- return NO_VETO;
- }
-
- /**
- * Called when an entity is passed to {@code Session.update()}.
- * This method is not called every time the object's
- * state is persisted during a flush.
- * @param s the session
- * @return true to veto update
- * @throws CallbackException Indicates a problem happened during callback
- */
- default boolean onUpdate(Session s) throws CallbackException {
- return NO_VETO;
- }
-
- /**
- * Called when an entity is deleted.
- * @param s the session
- * @return true to veto delete
- * @throws CallbackException Indicates a problem happened during callback
- */
- default boolean onDelete(Session s) throws CallbackException {
- return NO_VETO;
- }
-
- /**
- * Called after an entity is loaded. It is illegal to
- * access the {@code Session} from inside this method.
- * However, the object may keep a reference to the session
- * for later use.
- *
- * @param s the session
- * @param id the identifier
- */
- default void onLoad(Session s, Object id) {
- if (id==null || id instanceof Serializable) {
- onLoad(s, (Serializable) id);
- }
- }
-
- /**
- * Called after an entity is loaded. It is illegal to
- * access the {@code Session} from inside this method.
- * However, the object may keep a reference to the session
- * for later use.
- *
- * @param s the session
- * @param id the identifier
- *
- * @deprecated use {@link #onLoad(Session, Object)}
- */
- @Deprecated(since = "6.0")
- default void onLoad(Session s, Serializable id) {}
-}
diff --git a/hibernate-core/src/main/java/org/hibernate/classic/package-info.java b/hibernate-core/src/main/java/org/hibernate/classic/package-info.java
deleted file mode 100644
index 41e41fea79..0000000000
--- a/hibernate-core/src/main/java/org/hibernate/classic/package-info.java
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 http://www.gnu.org/licenses/lgpl-2.1.html
- */
-
-/**
- * This package historically provided backward-compatibility
- * with Hibernate 2.1 APIs which were deprecated in Hibernate 3.
- */
-package org.hibernate.classic;
diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java
index 340fb81da2..0541961b31 100644
--- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java
+++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java
@@ -11,7 +11,6 @@ import org.hibernate.NonUniqueObjectException;
import org.hibernate.action.internal.AbstractEntityInsertAction;
import org.hibernate.action.internal.EntityIdentityInsertAction;
import org.hibernate.action.internal.EntityInsertAction;
-import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.spi.CascadingAction;
@@ -215,12 +214,7 @@ public abstract class AbstractSaveEventListener implements CallbackRegistryCo
}
final EntityKey key = useIdentityColumn ? null : entityKey( id, persister, source );
- if ( invokeSaveLifecycle( entity, persister, source ) ) {
- return id;
- }
- else {
- return performSaveOrReplicate( entity, key, persister, useIdentityColumn, context, source, delayIdentityInserts );
- }
+ return performSaveOrReplicate( entity, key, persister, useIdentityColumn, context, source, delayIdentityInserts );
}
private static EntityKey entityKey(Object id, EntityPersister persister, EventSource source) {
@@ -241,19 +235,6 @@ public abstract class AbstractSaveEventListener implements CallbackRegistryCo
return key;
}
- protected boolean invokeSaveLifecycle(Object entity, EntityPersister persister, EventSource source) {
- // Sub-insertions should occur before containing insertion so
- // Try to do the callback now
- if ( persister.implementsLifecycle() ) {
- LOG.debug( "Calling onSave()" );
- if ( ((Lifecycle) entity).onSave( source ) ) {
- LOG.debug( "Insertion vetoed by onSave()" );
- return true;
- }
- }
- return false;
- }
-
/**
* Performs all the actual work needed to save an entity (well to get the save moved to
* the execution queue).
diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java
index dcd857ebce..59b253f7fa 100644
--- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java
+++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java
@@ -14,7 +14,6 @@ import org.hibernate.action.internal.EntityDeleteAction;
import org.hibernate.action.internal.OrphanRemovalAction;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
-import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.internal.ForeignKeys;
@@ -271,20 +270,18 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
Object id,
Object version,
EntityEntry entityEntry) {
- callbackRegistry.preRemove(entity);
- if ( !invokeDeleteLifecycle( source, entity, persister ) ) {
- deleteEntity(
- source,
- entity,
- entityEntry,
- event.isCascadeDeleteEnabled(),
- event.isOrphanRemovalBeforeUpdates(),
- persister,
- transientEntities
- );
- if ( source.getFactory().getSessionFactoryOptions().isIdentifierRollbackEnabled() ) {
- persister.resetIdentifier( entity, id, version, source );
- }
+ callbackRegistry.preRemove( entity );
+ deleteEntity(
+ source,
+ entity,
+ entityEntry,
+ event.isCascadeDeleteEnabled(),
+ event.isOrphanRemovalBeforeUpdates(),
+ persister,
+ transientEntities
+ );
+ if ( source.getFactory().getSessionFactoryOptions().isIdentifierRollbackEnabled() ) {
+ persister.resetIdentifier( entity, id, version, source );
}
}
@@ -293,7 +290,6 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
*/
private boolean canBeDeletedWithoutLoading(EventSource source, EntityPersister persister) {
return source.getInterceptor() == EmptyInterceptor.INSTANCE
- && !persister.implementsLifecycle()
&& !persister.hasSubclasses() //TODO: should be unnecessary, using EntityPersister.getSubclassPropertyTypeClosure(), etc
&& !persister.hasCascadeDelete()
&& !persister.hasNaturalIdentifier()
@@ -488,17 +484,6 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
return deletedState;
}
- protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
- if ( persister.implementsLifecycle() ) {
- LOG.debug( "Calling onDelete()" );
- if ( ( (Lifecycle) entity ).onDelete( session ) ) {
- LOG.debug( "Deletion vetoed by onDelete()" );
- return true;
- }
- }
- return false;
- }
-
protected void cascadeBeforeDelete(
EventSource session,
EntityPersister persister,
diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java
index 92a1236293..ecced24d54 100644
--- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java
+++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java
@@ -10,7 +10,6 @@ import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.action.internal.EntityIncrementVersionProcess;
import org.hibernate.action.internal.EntityVerifyVersionProcess;
-import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.PostLoadEvent;
@@ -20,11 +19,7 @@ import org.hibernate.jpa.event.spi.CallbackRegistryConsumer;
import org.hibernate.persister.entity.EntityPersister;
/**
- * We do two things here:
- *
- * - Call {@link Lifecycle} interface if necessary
- * - Perform needed {@link EntityEntry#getLockMode()} related processing
- *
+ * Performs needed {@link EntityEntry#getLockMode()}-related processing.
*
* @author Gavin King
* @author Steve Ebersole
@@ -72,13 +67,5 @@ public class DefaultPostLoadEventListener implements PostLoadEventListener, Call
+ "] not supported for non-versioned entities [" + persister.getEntityName() + "]");
}
}
-
- invokeLoadLifecycle( event, session );
- }
-
- protected void invokeLoadLifecycle(PostLoadEvent event, EventSource session) {
- if ( event.getPersister().implementsLifecycle() ) {
- ( (Lifecycle) event.getEntity() ).onLoad( session, event.getId() );
- }
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java
index 50c0709428..4cccd69632 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java
@@ -16,7 +16,6 @@ import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer;
-import org.hibernate.classic.Lifecycle;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
@@ -59,7 +58,6 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
private final JavaType> proxyJtd;
private final boolean isBytecodeEnhanced;
- private final boolean lifecycleImplementor;
private final ReflectionOptimizer reflectionOptimizer;
private final ProxyFactory proxyFactory;
@@ -89,7 +87,6 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
this.proxyJtd = null;
}
- this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedJavaType );
this.isBytecodeEnhanced = isPersistentAttributeInterceptableType( mappedJavaType );
final Property identifierProperty = bootDescriptor.getIdentifierProperty();
@@ -389,11 +386,6 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
return proxyFactory;
}
- @Override
- public boolean isLifecycleImplementor() {
- return lifecycleImplementor;
- }
-
@Override
public boolean isBytecodeEnhanced() {
return isBytecodeEnhanced;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java
index cc2376a501..da87e98b00 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java
@@ -27,10 +27,6 @@ public interface EntityRepresentationStrategy extends ManagedTypeRepresentationS
*/
ProxyFactory getProxyFactory();
- default boolean isLifecycleImplementor() {
- return false;
- }
-
default boolean isBytecodeEnhanced() {
return false;
}
diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
index 80811405f8..6f29f54e90 100644
--- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
+++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
@@ -40,7 +40,6 @@ import org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl;
import org.hibernate.cache.spi.entry.StandardCacheEntryImpl;
import org.hibernate.cache.spi.entry.StructuredCacheEntry;
import org.hibernate.cache.spi.entry.UnstructuredCacheEntry;
-import org.hibernate.classic.Lifecycle;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.lock.LockingStrategy;
@@ -464,8 +463,6 @@ public abstract class AbstractEntityPersister
*/
private final EntityPropertyMapping propertyMapping;
- private final boolean implementsLifecycle;
-
private List uniqueKeyEntries = null; //lazily initialized
private ConcurrentHashMap nonLazyPropertyLoadPlansByName;
@@ -523,7 +520,6 @@ public abstract class AbstractEntityPersister
javaType = representationStrategy.getLoadJavaType();
assert javaType != null;
- this.implementsLifecycle = Lifecycle.class.isAssignableFrom( javaType.getJavaTypeClass() );
concreteProxy = entityMetamodel.isPolymorphic()
&& ( getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() || hasProxy() )
@@ -4181,11 +4177,6 @@ public abstract class AbstractEntityPersister
return this.getMappedJavaType().getJavaTypeClass();
}
- @Override
- public boolean implementsLifecycle() {
- return this.implementsLifecycle;
- }
-
@Override
public Class> getConcreteProxyClass() {
final JavaType> proxyJavaType = getRepresentationStrategy().getProxyJavaType();
diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java
index b81b8dd999..7fa34208a7 100644
--- a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java
+++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java
@@ -537,8 +537,7 @@ public interface EntityPersister extends EntityMappingType, EntityMutationTarget
JdbcValueBiConsumer valueConsumer,
SharedSessionContractImplementor session) {
int span = 0;
- if ( domainValue instanceof Object[] ) {
- final Object[] values = (Object[]) domainValue;
+ if ( domainValue instanceof Object[] values ) {
for ( int i = 0; i < getNumberOfAttributeMappings(); i++ ) {
final AttributeMapping attributeMapping = getAttributeMapping( i );
span += attributeMapping.breakDownJdbcValues( values[ i ], offset + span, x, y, valueConsumer, session );
@@ -1078,11 +1077,6 @@ public interface EntityPersister extends EntityMappingType, EntityMutationTarget
*/
Class> getMappedClass();
- /**
- * Does the class implement the {@link org.hibernate.classic.Lifecycle} interface?
- */
- boolean implementsLifecycle();
-
/**
* Get the proxy interface that instances of this concrete class will be
* cast to (optional operation).
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java
index bc2fe852e5..9a2e957ec3 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java
@@ -617,11 +617,6 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver {
return null;
}
- @Override
- public boolean implementsLifecycle() {
- return false;
- }
-
@Override
public Class> getConcreteProxyClass() {
return null;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java
index 744917ba6a..36b43d5550 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java
@@ -639,11 +639,6 @@ public class PersisterClassProviderTest {
return null;
}
- @Override
- public boolean implementsLifecycle() {
- return false;
- }
-
@Override
public Class getConcreteProxyClass() {
return null;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java
index a73374d499..4a4ee2bdbf 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java
@@ -284,11 +284,6 @@ public class CustomPersister implements EntityPersister {
public void processUpdateGeneratedProperties(Object id, Object entity, Object[] state, GeneratedValues generatedValues, SharedSessionContractImplementor session) {
}
- @Override
- public boolean implementsLifecycle() {
- return false;
- }
-
@Override
public Class> getConcreteProxyClass() {
return Custom.class;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Foo.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Foo.java
index 4391066377..bc1779d0fd 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Foo.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Foo.java
@@ -9,11 +9,13 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import jakarta.persistence.PostLoad;
+import jakarta.persistence.PrePersist;
+import jakarta.persistence.PreRemove;
+import jakarta.persistence.PreUpdate;
import org.hibernate.CallbackException;
-import org.hibernate.Session;
-import org.hibernate.classic.Lifecycle;
-public class Foo implements Lifecycle, FooProxy, Serializable {
+public class Foo implements FooProxy, Serializable {
private static int count=0;
@@ -89,7 +91,8 @@ public class Foo implements Lifecycle, FooProxy, Serializable {
this.x=x;
}
- public boolean onSave(Session db) throws CallbackException {
+ @PrePersist
+ public void onSave() throws CallbackException {
_string = "a string";
_date = new Date(123);
_timestamp = new Date( System.currentTimeMillis() );
@@ -114,17 +117,6 @@ public class Foo implements Lifecycle, FooProxy, Serializable {
dependent = new Fee();
dependent.setFi( "belongs to foo # " + getKey() );
theLocale = Locale.getDefault();
- return NO_VETO;
- }
-
- public boolean onDelete(Session db) throws CallbackException {
- return NO_VETO;
- }
- public boolean onUpdate(Session db) throws CallbackException {
- return NO_VETO;
- }
-
- public void onLoad(Session db, Object id) {
}
public String getKey() {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Fum.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Fum.java
index 726ebbb26e..dc846cbcdf 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Fum.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Fum.java
@@ -4,20 +4,13 @@
*/
package org.hibernate.orm.test.legacy;
import java.io.Serializable;
-import java.sql.SQLException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.hibernate.CallbackException;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.classic.Lifecycle;
-
-public class Fum implements Lifecycle, Serializable {
+public class Fum implements Serializable {
private String fum;
private FumCompositeID id;
private Fum fo;
@@ -30,7 +23,7 @@ public class Fum implements Lifecycle, Serializable {
private MapComponent mapComponent = new MapComponent();
public Fum() {}
- public Fum(FumCompositeID id) throws SQLException, HibernateException {
+ public Fum(FumCompositeID id) {
this.id = id;
friends = new HashSet();
FumCompositeID fid = new FumCompositeID();
@@ -76,45 +69,6 @@ public class Fum implements Lifecycle, Serializable {
this.friends = friends;
}
-
- public boolean onDelete(Session s) throws CallbackException {
- if (friends==null) return false;
- try {
- Iterator iter = friends.iterator();
- while ( iter.hasNext() ) {
- s.remove( iter.next() );
- }
- }
- catch (Exception e) {
- throw new CallbackException(e);
- }
- return false;
- }
-
-
- public void onLoad(Session s, Object id) {
- }
-
-
- public boolean onSave(Session s) throws CallbackException {
- if (friends==null) return false;
- try {
- Iterator iter = friends.iterator();
- while ( iter.hasNext() ) {
- s.persist( iter.next() );
- }
- }
- catch (Exception e) {
- throw new CallbackException(e);
- }
- return false;
- }
-
-
- public boolean onUpdate(Session s) throws CallbackException {
- return false;
- }
-
public Calendar getLastUpdated() {
return lastUpdated;
}
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Glarch.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Glarch.java
index 8c9ca4594f..682e6c3edd 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Glarch.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Glarch.java
@@ -9,11 +9,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import jakarta.persistence.PrePersist;
import org.hibernate.CallbackException;
-import org.hibernate.Session;
-import org.hibernate.classic.Lifecycle;
-public class Glarch extends Super implements GlarchProxy, Lifecycle, Named, Serializable {
+public class Glarch extends Super implements GlarchProxy, Named, Serializable {
private int version;
private GlarchProxy next;
@@ -97,34 +96,14 @@ public class Glarch extends Super implements GlarchProxy, Lifecycle, Named, Seri
this.proxySet = proxySet;
}
- public boolean onDelete(Session s) throws CallbackException {
- return NO_VETO;
- }
-
- public void onLoad(Session s, Object id) {
- if ( ! ( ( (String) id ).length()==32 ) ) throw new RuntimeException("id problem");
- }
-
- public boolean onSave(Session s) throws CallbackException {
+ @PrePersist
+ public void onSave() throws CallbackException {
dynaBean = new HashMap();
dynaBean.put("foo", "foo");
dynaBean.put("bar", new Integer(66));
immutable="never changes!";
- return NO_VETO;
}
- public boolean onUpdate(Session s) throws CallbackException {
- return NO_VETO;
- }
-
- /*public Currency getCurrency() {
- return currency;
- }
-
- public void setCurrency(Currency currency) {
- this.currency = currency;
- }*/
-
/**
* Returns the dynaBean.
* @return DynaBean
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Qux.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Qux.java
index cbc3360202..195a981dd5 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Qux.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Qux.java
@@ -7,12 +7,11 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Set;
-import org.hibernate.CallbackException;
+import jakarta.persistence.PostLoad;
import org.hibernate.HibernateException;
import org.hibernate.Session;
-import org.hibernate.classic.Lifecycle;
-public class Qux implements Lifecycle {
+public class Qux {
boolean created;
boolean deleted;
@@ -35,31 +34,7 @@ public class Qux implements Lifecycle {
stuff=s;
}
- public boolean onSave(Session session) throws CallbackException {
- created=true;
- try {
- foo = new Foo();
- session.persist(foo);
- }
- catch (Exception e) {
- throw new CallbackException(e);
- }
- foo.setString("child of a qux");
- return NO_VETO;
- }
-
- public boolean onDelete(Session session) throws CallbackException {
- deleted=true;
- try {
- session.remove(foo);
- }
- catch (Exception e) {
- throw new CallbackException(e);
- }
- //if (child!=null) session.remove(child);
- return NO_VETO;
- }
-
+ @PostLoad
public void onLoad(Session session, Object id) {
loaded=true;
this.session=session;
@@ -157,10 +132,6 @@ public class Qux implements Lifecycle {
this.childKey = childKey;
}
- public boolean onUpdate(Session s) throws CallbackException {
- return NO_VETO;
- }
-
protected void finalize() { }
public Holder getHolder() {
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Vetoer.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Vetoer.java
deleted file mode 100644
index 6737296882..0000000000
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Vetoer.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-or-later
- * Copyright Red Hat Inc. and Hibernate Authors
- */
-package org.hibernate.orm.test.legacy;
-
-import org.hibernate.CallbackException;
-import org.hibernate.Session;
-import org.hibernate.classic.Lifecycle;
-
-public class Vetoer implements Lifecycle {
- private String id;
- private String name;
- private String[] strings;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String[] getStrings() {
- return strings;
- }
-
- public void setStrings(String[] strings) {
- this.strings = strings;
- }
-
- boolean onSaveCalled;
- boolean onUpdateCalled;
- boolean onDeleteCalled;
-
- public boolean onSave(Session s) throws CallbackException {
- boolean result = !onSaveCalled;
- onSaveCalled = true;
- return result;
- }
-
- public boolean onUpdate(Session s) throws CallbackException {
- boolean result = !onUpdateCalled;
- onUpdateCalled = true;
- return result;
- }
-
- public boolean onDelete(Session s) throws CallbackException {
- boolean result = !onDeleteCalled;
- onDeleteCalled = true;
- return result;
- }
-
- public void onLoad(Session s, Object id) {}
-}
diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/legacy/Vetoer.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/legacy/Vetoer.hbm.xml
deleted file mode 100644
index 033a664cc7..0000000000
--- a/hibernate-core/src/test/resources/org/hibernate/orm/test/legacy/Vetoer.hbm.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file