List of usage examples for org.hibernate.proxy LazyInitializer unsetSession
void unsetSession();
From source file:org.jspresso.framework.application.backend.persistence.hibernate.HibernateHelper.java
License:Open Source License
/** * Unset proxy hibernate session.// w w w . j a v a 2 s.co m * * @param entity the entity * @param hibernateSession the hibernate session */ public static void unsetProxyHibernateSession(IEntity entity, Session hibernateSession) { if (entity instanceof HibernateProxy) { LazyInitializer li = ((HibernateProxy) entity).getHibernateLazyInitializer(); if (li.getSession() != null && li.getSession() != hibernateSession) { li.unsetSession(); } } }
From source file:org.web4thejob.orm.MetaReaderServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <E extends Entity> E deproxyEntity(E entity) { final E proxy = entity; if (proxy instanceof HibernateProxy) { {/*from www. j a v a 2 s. c om*/ if (((HibernateProxy) proxy).getHibernateLazyInitializer().isUninitialized()) { final E impl = ContextUtil.getTransactionWrapper().execute(new TransactionCallback<E>() { @Override public E doInTransaction(TransactionStatus status) { final LazyInitializer lazy = ((HibernateProxy) proxy).getHibernateLazyInitializer(); lazy.setSession((SessionImplementor) sessionFactory.getCurrentSession()); lazy.initialize(); final Object impl = lazy.getImplementation(); lazy.unsetSession(); return (E) impl; } }); return impl; } else { return (E) ((HibernateProxy) proxy).getHibernateLazyInitializer().getImplementation(); } } } return entity; }