29 lines
656 B
Java
29 lines
656 B
Java
package com.jasamedika.medifirst2000.util;
|
|
|
|
import org.hibernate.Hibernate;
|
|
import org.hibernate.proxy.HibernateProxy;
|
|
|
|
public class HibernateInitialize {
|
|
public static <T> T initializeAndUnproxy(T entity) {
|
|
if (entity == null) {
|
|
throw new
|
|
NullPointerException("Entity passed for initialization is null");
|
|
}
|
|
|
|
try
|
|
{
|
|
Hibernate.initialize(entity);
|
|
if (entity instanceof HibernateProxy) {
|
|
entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer()
|
|
.getImplementation();
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
}
|