/** * Handle the given update event. * * @param event The update event to be handled. */ public void onSaveOrUpdate(SaveOrUpdateEvent event) { final SessionImplementor source = event.getSession(); final Object object = event.getObject(); final Serializable requestedId = event.getRequestedId(); if ( requestedId != null ) { //assign the requested id to the proxy, *before* //reassociating the proxy if ( object instanceof HibernateProxy ) { ( (HibernateProxy) object ).getHibernateLazyInitializer().setIdentifier( requestedId ); } } // For an uninitialized proxy, noop, don't even need to return an id, since it is never a save() if ( reassociateIfUninitializedProxy( object, source ) ) { LOG.trace( "Reassociated uninitialized proxy" ); } else { //initialize properties of the event: final Object entity = source.getPersistenceContext().unproxyAndReassociate( object ); event.setEntity( entity ); event.setEntry( source.getPersistenceContext().getEntry( entity ) ); //return the id in the event object event.setResultId( performSaveOrUpdate( event ) ); } }
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
loadedValue = eventSource.getPersistenceContext().unproxyAndReassociate( loadedValue ); valueEntry = eventSource.getPersistenceContext().getEntry( loadedValue );
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
final Object object = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionImplementor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaContext; import org.springframework.stereotype.Component; @Component public final class JpaHibernateUtil { private static JpaContext jpaContext; @Autowired JpaHibernateUtil(JpaContext jpaContext) { JpaHibernateUtil.jpaContext = jpaContext; } public static <Type> Type unproxy(Type proxied, Class<Type> type) { PersistenceContext persistenceContext = jpaContext .getEntityManagerByManagedType(type) .unwrap(SessionImplementor.class) .getPersistenceContext(); Type unproxied = (Type) persistenceContext.unproxyAndReassociate(proxied); return unproxied; } }
@Override public Object unproxy(Object value) { if ( value instanceof HibernateProxy ) { final HibernateProxy proxy = (HibernateProxy) value; final LazyInitializer lazyInitializer = proxy.getHibernateLazyInitializer(); Object initialized = lazyInitializer.getImplementation( sessionImplementor ); if ( initialized != null ) { return initialized; } else { // This is the case in which the proxy was created by a different session. // unproxyAndReassociate is the ultimate bomb, // able to deal with a Session change: return sessionImplementor.getPersistenceContext().unproxyAndReassociate( proxy ); } } return value; }
@Override public Object unproxy(Object instance) { if ( instance instanceof HibernateProxy ) { final HibernateProxy proxy = (HibernateProxy) instance; final LazyInitializer lazyInitializer = proxy.getHibernateLazyInitializer(); Object initialized = lazyInitializer.getImplementation( hibernateSession ); if ( initialized != null ) { return initialized; } else { // This is the case in which the proxy was created by a different session. // unproxyAndReassociate is the ultimate bomb, // able to deal with a Session change: return hibernateSession.getPersistenceContext().unproxyAndReassociate( proxy ); } } return instance; }
/** * Handle the given update event. * * @param event The update event to be handled. */ public void onSaveOrUpdate(SaveOrUpdateEvent event) { final SessionImplementor source = event.getSession(); final Object object = event.getObject(); final Serializable requestedId = event.getRequestedId(); if ( requestedId != null ) { //assign the requested id to the proxy, *before* //reassociating the proxy if ( object instanceof HibernateProxy ) { ( ( HibernateProxy ) object ).getHibernateLazyInitializer().setIdentifier( requestedId ); } } // For an uninitialized proxy, noop, don't even need to return an id, since it is never a save() if ( reassociateIfUninitializedProxy( object, source ) ) { LOG.trace( "Reassociated uninitialized proxy" ); } else { //initialize properties of the event: final Object entity = source.getPersistenceContext().unproxyAndReassociate( object ); event.setEntity( entity ); event.setEntry( source.getPersistenceContext().getEntry( entity ) ); //return the id in the event object event.setResultId( performSaveOrUpdate( event ) ); } }
/** * Handle the given update event. * * @param event The update event to be handled. */ public void onSaveOrUpdate(SaveOrUpdateEvent event) { final SessionImplementor source = event.getSession(); final Object object = event.getObject(); final Serializable requestedId = event.getRequestedId(); if ( requestedId != null ) { //assign the requested id to the proxy, *before* //reassociating the proxy if ( object instanceof HibernateProxy ) { ( ( HibernateProxy ) object ).getHibernateLazyInitializer().setIdentifier( requestedId ); } } // For an uninitialized proxy, noop, don't even need to return an id, since it is never a save() if ( reassociateIfUninitializedProxy( object, source ) ) { LOG.trace( "Reassociated uninitialized proxy" ); } else { //initialize properties of the event: final Object entity = source.getPersistenceContext().unproxyAndReassociate( object ); event.setEntity( entity ); event.setEntry( source.getPersistenceContext().getEntry( entity ) ); //return the id in the event object event.setResultId( performSaveOrUpdate( event ) ); } }
/** * Handle the given update event. * * @param event The update event to be handled. */ public void onSaveOrUpdate(SaveOrUpdateEvent event) { final SessionImplementor source = event.getSession(); final Object object = event.getObject(); final Object requestedId = event.getRequestedId(); if ( requestedId != null ) { //assign the requested id to the proxy, *before* //reassociating the proxy if ( object instanceof HibernateProxy ) { ( (HibernateProxy) object ).getHibernateLazyInitializer().setIdentifier( requestedId ); } } // For an uninitialized proxy, noop, don't even need to return an id, since it is never a save() if ( reassociateIfUninitializedProxy( object, source ) ) { LOG.trace( "Reassociated uninitialized proxy" ); } else { //initialize properties of the event: final Object entity = source.getPersistenceContext().unproxyAndReassociate( object ); event.setEntity( entity ); event.setEntry( source.getPersistenceContext().getEntry( entity ) ); //return the id in the event object event.setResultId( performSaveOrUpdate( event ) ); } }
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
final Object object = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );