开发者

introspection - table name of an object managed by Hibernate (JavassistLazyInitializer)

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 ha开发者_StackOverflow社区ndler.

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜