内省 - Hibernate 管理的对象的表名 (JavassistLazyInitializer)

发布于 2024-09-24 15:35:19 字数 261 浏览 2 评论 0原文

我想通过内省获得 Hibernate 管理的对象的表名(惰性)。

我的对象在属性处理程序中包含“org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer”。

我的对象的类型为“mypackage.myObjectDO_ _javassist_2 $ $”,并且不包含类“mypackage.myObjectDO”包含的注释(我寻找注释javax.persistence.Table)。

我该怎么办?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-10-01 15:35:19

我想通过自省获得 Hibernate 管理的对象的表名(惰性)。

这是一个不寻常的需求(Hibernate 应该将其抽象化),但假设您确实需要它......

我的对象属于 (...) 类型,并且不包含类 (...) 所包含的注释

您必须取消代理代理。这是以前的答案(来自 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;
}

另请参阅将代理对象转换为真实对象 Hibernate 论坛。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文