public Session getSession() { if (session == null) { if (entityManager.getDelegate() instanceof EntityManagerImpl) { EntityManagerImpl entityManagerImpl = (EntityManagerImpl) entityManager.getDelegate(); return entityManagerImpl.getSession(); } else { return (Session) entityManager.getDelegate(); } } else { return session; } }
@Around("execution(java.util.* com.acme.domain.**.get*())") public Object lazy(ProceedingJoinPoint pjp) throws Throwable { Object res = pjp.proceed(); if (res instanceof AbstractPersistentCollection && !((AbstractPersistentCollection) res).wasInitialized()) { EntityManagerImpl em = (EntityManagerImpl) Persistence.createEntityManagerFactory("jpa").createEntityManager(); em.getSession().replicate(pjp.getThis(), ReplicationMode.LATEST_VERSION); res.equals(null); em.close(); } return res; }