Class TransientReferenceResolvingInterceptor
- All Implemented Interfaces:
Serializable,org.hibernate.Interceptor
When found, it automatically resolves and replaces the transient entity reference with an active, managed reference (proxy) from the current persistence context to avoid TransientPropertyValueException.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTransientReferenceResolvingInterceptor(org.springframework.beans.factory.ObjectProvider<jakarta.persistence.EntityManagerFactory> entityManagerFactoryProvider) -
Method Summary
Modifier and TypeMethodDescriptionisTransient(Object entity) Distinguishes transient (new) from detached (already persisted) entities without using Hibernate'sgetDatabaseSnapshot()fallback.booleanonFlushDirty(Object entity, Object id, Object[] currentState, Object[] previousState, String[] propertyNames, org.hibernate.type.Type[] types) booleanonPersist(Object entity, Object id, Object[] state, String[] propertyNames, org.hibernate.type.Type[] types) booleanonSave(Object entity, Object id, Object[] state, String[] propertyNames, org.hibernate.type.Type[] types) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.Interceptor
afterTransactionBegin, afterTransactionCompletion, beforeTransactionCompletion, findDirty, getEntity, getEntityName, instantiate, instantiate, onCollectionRecreate, onCollectionRemove, onCollectionUpdate, onDelete, onDelete, onInsert, onLoad, onRemove, onUpdate, onUpsert, postFlush, postMerge, preFlush, preMerge
-
Constructor Details
-
TransientReferenceResolvingInterceptor
public TransientReferenceResolvingInterceptor(org.springframework.beans.factory.ObjectProvider<jakarta.persistence.EntityManagerFactory> entityManagerFactoryProvider)
-
-
Method Details
-
isTransient
Distinguishes transient (new) from detached (already persisted) entities without using Hibernate'sgetDatabaseSnapshot()fallback.Under Hibernate 7 that snapshot load builds an embeddable result with no owning entity initializer, so any
@Parentparent-injection embeddable -- such as the tracking embeddable present on every tracked entity -- fails with"Injection of parent instance into embeddable result is not possible". Hibernate reaches that path when checking whether an assigned-id@ManyToOnereference is transient before an insert. By answering definitively here (using a normal, snapshot-safe load-by-id), Hibernate never falls through to the crashing snapshot query.- Specified by:
isTransientin interfaceorg.hibernate.Interceptor- Returns:
FALSEif the entity already exists (managed or found in the database),TRUEif it is brand new, ornullto defer to Hibernate's default when this interceptor cannot make a determination.
-
onSave
public boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, org.hibernate.type.Type[] types) - Specified by:
onSavein interfaceorg.hibernate.Interceptor
-
onPersist
public boolean onPersist(Object entity, Object id, Object[] state, String[] propertyNames, org.hibernate.type.Type[] types) - Specified by:
onPersistin interfaceorg.hibernate.Interceptor
-
onFlushDirty
public boolean onFlushDirty(Object entity, Object id, Object[] currentState, Object[] previousState, String[] propertyNames, org.hibernate.type.Type[] types) - Specified by:
onFlushDirtyin interfaceorg.hibernate.Interceptor
-