From the answer under this question, we know that we can use following code to unproxy and get the real entity class:
public static <T> T initializeAndUnproxy(T entity) {
if (entity == null) {
throw new
NullPointerException("Entity passed for initialization is null");
}
Hibernate.initialize(entity);
if (entity instanceof HibernateProxy) {
entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer()
.getImplementation();
}
return entity;
}
However, I am afraid that using this method will make the program send sql query to database to retrieve all field that have not retrieved yet, leading to worse performance of my program. Is there any way to get around this but still get the unproxy entity class?