Best code examples for Hibernate ORM PersistenceContext class (org.hibernate.engine.spi.PersistenceContext)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM PersistenceContext class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Hibernate ORM PersistenceContext examples from Open Source projects
This code example shows how to use the following methods: addEntity, checkUniqueness, getEntry, unproxyAndReassociate
	 */ 
	public void onDelete(DeleteEvent event, Set transientEntities) throws HibernateException { 
 
		final EventSource source = event.getSession(); 
 
		final PersistenceContext persistenceContext = source.getPersistenceContext(); 
		Object entity = persistenceContext.unproxyAndReassociate( event.getObject() ); 
 
		EntityEntry entityEntry = persistenceContext.getEntry( entity ); 
		final EntityPersister persister; 
		final Serializable id; 
		final Object version; 
 
		if ( entityEntry == null ) { 
            LOG.trace("Entity was not persistent in delete processing"); 
 
			persister = source.getEntityPersister( event.getEntityName(), entity ); 
 
			if ( ForeignKeys.isTransient( persister.getEntityName(), entity, null, source ) ) { 
				deleteTransientEntity( source, entity, event.isCascadeDeleteEnabled(), persister, transientEntities ); 

6
CodeRank
This code example shows how to use the following methods: addCollectionHolder, addNewCollection, getCollectionHolder
			//TODO: move into collection type, so we can use polymorphism! 
			if ( collectionType.hasHolder() ) { 
 
				if (collection==CollectionType.UNFETCHED_COLLECTION) return null; 
 
				PersistentCollection ah = persistenceContext.getCollectionHolder(collection); 
				if (ah==null) { 
					ah = collectionType.wrap(session, collection); 
					persistenceContext.addNewCollection( persister, ah ); 
					persistenceContext.addCollectionHolder(ah); 
				} 
				return null; 
			} 
			else { 
 
				PersistentCollection persistentCollection = collectionType.wrap(session, collection); 
				persistenceContext.addNewCollection( persister, persistentCollection ); 
 
                if (LOG.isTraceEnabled()) LOG.trace("Wrapped collection in role: " + collectionType.getRole()); 
 

5
CodeRank
This code example shows how to use the following methods: getCollectionEntry, getEntity, getEntry
			processDereferencedCollection(coll, session); 
		} 
	} 
 
	private static void processDereferencedCollection(PersistentCollection coll, SessionImplementor session) { 
		final PersistenceContext persistenceContext = session.getPersistenceContext(); 
		CollectionEntry entry = persistenceContext.getCollectionEntry(coll); 
		final CollectionPersister loadedPersister = entry.getLoadedPersister(); 
 
        if (LOG.isDebugEnabled() && loadedPersister != null) { 
			LOG.debugf( 
					"Collection dereferenced: %s", 
					MessageHelper.collectionInfoString( 
							loadedPersister, 
							entry.getLoadedKey(), 
							session.getFactory() 
					) 
			); 
		} 
 

5
CodeRank
This code example shows how to use the following methods: getSession, removeEntry
				final Object entity = persistenceContext.removeEntity( key ); 
				if ( entity != null ) { 
					EntityEntry e = event.getSession().getPersistenceContext().removeEntry( entity ); 
					doEvict( entity, key, e.getPersister(), event.getSession() ); 
				} 
			} 
			li.unsetSession(); 
		} 
		else { 
			EntityEntry e = persistenceContext.removeEntry( object ); 
			if ( e != null ) { 
				persistenceContext.removeEntity( e.getEntityKey() ); 
				doEvict( object, e.getEntityKey(), e.getPersister(), source ); 
			} 
		} 
	} 
 
	protected void doEvict( 
		final Object object, 
		final EntityKey key, 

5
CodeRank
This code example shows how to use the following methods: clear, getEntity, isLoadFinished
 
	public void refresh(String entityName, Object entity, LockMode lockMode) { 
		final EntityPersister persister = this.getEntityPersister( entityName, entity ); 
		final Serializable id = persister.getIdentifier( entity, this ); 
        if (LOG.isTraceEnabled()) LOG.trace("Refreshing transient " + MessageHelper.infoString(persister, id, this.getFactory())); 
		// TODO : can this ever happen??? 
//		EntityKey key = new EntityKey( id, persister, source.getEntityMode() ); 
//		if ( source.getPersistenceContext().getEntry( key ) != null ) { 
//			throw new PersistentObjectException( 
//					"attempted to refresh transient instance when persistent " + 
//					"instance was already associated with the Session: " + 
//					MessageHelper.infoString( persister, id, source.getFactory() ) 
//			); 
//		} 
 
		if ( persister.hasCache() ) { 
			final CacheKey ck = generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() ); 
			persister.getCacheAccessStrategy().evict( ck ); 
		} 
 

4
CodeRank
See Code Examples for Hibernate ORM PersistenceContext Methods: