Hibernate Lazy Download proxy not compatible with other platforms

I came across several examples where the frameworks that accept POJOs do some work with a beans hibernation proxy.

For example, if I xml annotate a bean for the X framework and pass it to the X framework, it will not recognize the bean because it will be passed a proxy object that has no annotations for the X framework.

Is there a general solution? I would rather not define the bean as impatient, load or rotate lazy loading anywhere in the application.

+3
source share
1 answer

You can disable an object before passing it:

public static <T> T initializeAndUnproxy(T var) {
    if (var == null) {
        throw new IllegalArgumentException("passed argument is null");
    }

    Hibernate.initialize(var);
    if (var instanceof HibernateProxy) {
        var = (T) ((HibernateProxy) var).getHibernateLazyInitializer()
                .getImplementation();
    }
    return var;
}
+5
source

Source: https://habr.com/ru/post/1748189/


All Articles