Java Code Examples for org.hibernate.proxy.LazyInitializer#getIdentifier()
The following examples show how to use
org.hibernate.proxy.LazyInitializer#getIdentifier() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Serializable getIdentifier(Object object) throws HibernateException { checkOpen(); checkTransactionSynchStatus(); if ( object instanceof HibernateProxy ) { LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); if ( li.getSession() != this ) { throw new TransientObjectException( "The proxy was not associated with this session" ); } return li.getIdentifier(); } else { EntityEntry entry = persistenceContext.getEntry( object ); if ( entry == null ) { throw new TransientObjectException( "The instance was not associated with this session" ); } return entry.getId(); } }
Example 2
Source File: SessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public Serializable getIdentifier(Object object) throws HibernateException { errorIfClosed(); checkTransactionSynchStatus(); if ( object instanceof HibernateProxy ) { LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); if ( li.getSession() != this ) { throw new TransientObjectException( "The proxy was not associated with this session" ); } return li.getIdentifier(); } else { EntityEntry entry = persistenceContext.getEntry(object); if ( entry == null ) { throw new TransientObjectException( "The instance was not associated with this session" ); } return entry.getId(); } }
Example 3
Source File: ReactiveSessionImpl.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
@Override public <T> CompletionStage<T> reactiveFetch(T association, boolean unproxy) { checkOpen(); if ( association instanceof HibernateProxy ) { LazyInitializer initializer = ((HibernateProxy) association).getHibernateLazyInitializer(); //TODO: is this correct? // SessionImpl doesn't use IdentifierLoadAccessImpl for initializing proxies String entityName = initializer.getEntityName(); Serializable identifier = initializer.getIdentifier(); return new ReactiveIdentifierLoadAccessImpl<T>( entityName ) .fetch( identifier ) .thenApply( SessionUtil.checkEntityFound( this, entityName, identifier ) ) .thenApply( entity -> { initializer.setSession( this ); initializer.setImplementation( entity ); return unproxy ? entity : association; } ); } else if ( association instanceof PersistentCollection ) { PersistentCollection persistentCollection = (PersistentCollection) association; return reactiveInitializeCollection( persistentCollection, false ) .thenApply( pc -> association ); } else { return CompletionStages.completedFuture( association ); } }
Example 4
Source File: StatefulPersistenceContext.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Associate a proxy that was instantiated by another session with this session * * @param li The proxy initializer. * @param proxy The proxy to reassociate. */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) { if ( li.getSession() != this.getSession() ) { EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() ); EntityKey key = new EntityKey( li.getIdentifier(), persister, session.getEntityMode() ); // any earlier proxy takes precedence if ( !proxiesByKey.containsKey( key ) ) { proxiesByKey.put( key, proxy ); } proxy.getHibernateLazyInitializer().setSession( session ); } }
Example 5
Source File: EntityType.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Get the identifier value of an instance or proxy. * <p/> * Intended only for loggin purposes!!! * * @param object The object from which to extract the identifier. * @param persister The entity persister * @param entityMode The entity mode * @return The extracted identifier. */ private static Serializable getIdentifier(Object object, EntityPersister persister, EntityMode entityMode) { if (object instanceof HibernateProxy) { HibernateProxy proxy = (HibernateProxy) object; LazyInitializer li = proxy.getHibernateLazyInitializer(); return li.getIdentifier(); } else { return persister.getIdentifier( object, entityMode ); } }
Example 6
Source File: Models.java From commafeed with Apache License 2.0 | 5 votes |
/** * extract the id from the proxy without initializing it */ public static Long getId(AbstractModel model) { if (model instanceof HibernateProxy) { LazyInitializer lazyInitializer = ((HibernateProxy) model).getHibernateLazyInitializer(); if (lazyInitializer.isUninitialized()) { return (Long) lazyInitializer.getIdentifier(); } } return model.getId(); }