Java Code Examples for org.hibernate.event.spi.EventSource#setCacheMode()

The following examples show how to use org.hibernate.event.spi.EventSource#setCacheMode() . 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: DefaultDeleteEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected void cascadeBeforeDelete(
		EventSource session,
		EntityPersister persister,
		Object entity,
		EntityEntry entityEntry,
		Set transientEntities) throws HibernateException {

	CacheMode cacheMode = session.getCacheMode();
	session.setCacheMode( CacheMode.GET );
	session.getPersistenceContext().incrementCascadeLevel();
	try {
		// cascade-delete to collections BEFORE the collection owner is deleted
		Cascade.cascade(
				CascadingActions.DELETE,
				CascadePoint.AFTER_INSERT_BEFORE_DELETE,
				session,
				persister,
				entity,
				transientEntities
		);
	}
	finally {
		session.getPersistenceContext().decrementCascadeLevel();
		session.setCacheMode( cacheMode );
	}
}
 
Example 2
Source File: DefaultDeleteEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected void cascadeAfterDelete(
		EventSource session,
		EntityPersister persister,
		Object entity,
		Set transientEntities) throws HibernateException {

	CacheMode cacheMode = session.getCacheMode();
	session.setCacheMode( CacheMode.GET );
	session.getPersistenceContext().incrementCascadeLevel();
	try {
		// cascade-delete to many-to-one AFTER the parent was deleted
		Cascade.cascade(
				CascadingActions.DELETE,
				CascadePoint.BEFORE_INSERT_AFTER_DELETE,
				session,
				persister,
				entity,
				transientEntities
		);
	}
	finally {
		session.getPersistenceContext().decrementCascadeLevel();
		session.setCacheMode( cacheMode );
	}
}