From d3114406df891805a7433c037886733b1e3714a9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 13 Dec 2024 00:30:04 +0100 Subject: [PATCH] finally kill of Lifecycle after all these years --- .../java/org/hibernate/CallbackException.java | 3 +- .../main/java/org/hibernate/Interceptor.java | 1 - .../java/org/hibernate/classic/Lifecycle.java | 125 ------------------ .../org/hibernate/classic/package-info.java | 12 -- .../internal/AbstractSaveEventListener.java | 21 +-- .../internal/DefaultDeleteEventListener.java | 39 ++---- .../DefaultPostLoadEventListener.java | 15 +-- ...ityRepresentationStrategyPojoStandard.java | 8 -- .../spi/EntityRepresentationStrategy.java | 4 - .../entity/AbstractEntityPersister.java | 9 -- .../persister/entity/EntityPersister.java | 8 +- .../GoofyPersisterClassProvider.java | 5 - .../PersisterClassProviderTest.java | 5 - .../orm/test/legacy/CustomPersister.java | 5 - .../org/hibernate/orm/test/legacy/Foo.java | 22 +-- .../org/hibernate/orm/test/legacy/Fum.java | 50 +------ .../org/hibernate/orm/test/legacy/Glarch.java | 29 +--- .../org/hibernate/orm/test/legacy/Qux.java | 35 +---- .../org/hibernate/orm/test/legacy/Vetoer.java | 63 --------- .../hibernate/orm/test/legacy/Vetoer.hbm.xml | 21 --- 20 files changed, 32 insertions(+), 448 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/classic/package-info.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/legacy/Vetoer.java delete mode 100644 hibernate-core/src/test/resources/org/hibernate/orm/test/legacy/Vetoer.hbm.xml diff --git a/hibernate-core/src/main/java/org/hibernate/CallbackException.java b/hibernate-core/src/main/java/org/hibernate/CallbackException.java index 5b695b0a38aa..02f4814be212 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 bca3937c083d..e40854b2f330 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 @@ * * @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 68db4fe33ab5..000000000000 --- 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. - * - *

- * {@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 41e41fea7952..000000000000 --- 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 340fb81da24f..0541961b3157 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.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 @@ protected Object performSave( } 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 @@ else if ( persistenceContext.containsDeletedUnloadedEntityKey( key ) ) { 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 dcd857ebcee5..59b253f7fa79 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.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 @@ private void delete( 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 @@ private void delete( */ 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 @@ else if ( currentState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY 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 92a1236293d9..ecced24d54d9 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.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.persister.entity.EntityPersister; /** - * We do two things here: - *

+ * Performs needed {@link EntityEntry#getLockMode()}-related processing. * * @author Gavin King * @author Steve Ebersole @@ -72,13 +67,5 @@ public void onPostLoad(PostLoadEvent event) { + "] 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 50c070942853..4cccd69632fa 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.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 EntityRepresentationStrategyPojoStandard( this.proxyJtd = null; } - this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedJavaType ); this.isBytecodeEnhanced = isPersistentAttributeInterceptableType( mappedJavaType ); final Property identifierProperty = bootDescriptor.getIdentifierProperty(); @@ -389,11 +386,6 @@ public ProxyFactory getProxyFactory() { 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 cc2376a5019a..da87e98b00e1 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 80811405f8cc..6f29f54e90c4 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.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 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 final Class getMappedClass() { 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 b81b8dd999c4..7fa34208a711 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 @@ default int breakDownJdbcValues( 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 @@ default List getUpdateGeneratedProperties() { */ 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 bc2fe852e5d4..9a2e957ec310 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 getMappedClass() { 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 744917ba6a23..36b43d5550d2 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 getMappedClass() { 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 a73374d49986..4a4ee2bdbfac 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 void processInsertGeneratedProperties(Object id, Object entity, Object[] 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 4391066377d8..bc1779d0fd4d 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.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 Foo(int x) { 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 boolean onSave(Session db) throws CallbackException { 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 726ebbb26e7d..dc846cbcdf7f 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 void setFriends(Set friends) { 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 8c9ca4594f88..682e6c3edde4 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.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 void setProxySet(Set proxySet) { 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 cbc33602028f..195a981dd5a7 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.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 Qux(String s) { 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 @@ private void setChildKey(Long childKey) { 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 6737296882af..000000000000 --- 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 033a664cc79e..000000000000 --- 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