0

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?

guo
  • 9,674
  • 9
  • 41
  • 79
  • Looks like an XY question: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Selaron Nov 20 '18 at 10:10
  • Why do you want to unwrap that proxy, what's the problem you actually want to solve? BTW: you are right, Hibernet will send SQL queries if the Proxy has not been initialized before. – Selaron Nov 20 '18 at 10:11

0 Answers0