views:

40

answers:

1

I want to get through introspection the table name of an object managed by Hibernate (in lazy).

my object contains "org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer" in the property handler.

my object is of type "mypackage.myObjectDO_ _javassist_2 $ $" and does not contain the annotations that the class "mypackage.myObjectDO" contains (I seek the annotation javax.persistence.Table).

How can I do?

A: 

I want to get through introspection the table name of an object managed by Hibernate (in lazy).

This is an unusual need (Hibernate is supposed to abstract that away) but let's say you really need it...

my object is of type (...) and does not contain the annotations that the class (...) contains

You'll have to unproxy the proxy. Here is a little method from a previous answer (from Bozho):

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;
}

See also Converting proxy object to the real thing in the Hibernate forums.

Pascal Thivent