用于 Hibernate 映射的自定义类加载器

发布于 2024-10-06 11:14:34 字数 334 浏览 0 评论 0原文

有谁知道拦截 Hibernate 调用以实例化 .hbm.xml 文件中指示的类的方法吗?我需要一种使用自定义类加载器来提供实例的方法。我一般不想更改 Hibernate 的类加载,只想更改映射的“POJO”类的实例化。

<hibernate-mapping>
    <class name="com.foo.Bar" table="Bar">

在上面的示例代码中,当 Hibernate 想要实例化 Bar 时,我需要为该类提供自定义代码,而不是依赖默认的类加载行为。

预先感谢您的任何见解,
萨埃蒂

Does anyone know a way to intercept the call Hibernate will make to instantiate a class indicated in a .hbm.xml file? I need a way to use a custom ClassLoader to provide an instance. I don't want to change class loading for Hibernate in general, just the instantiate of the mapped "POJO" class.

<hibernate-mapping>
    <class name="com.foo.Bar" table="Bar">

In the example code above, when Hibernate wants to instantiate Bar I need to provide that class with custom code instead of relying on the default class loading behavior.

Thanks in advance for any insight,
saethi

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

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

发布评论

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

评论(1

白昼 2024-10-13 11:14:34

您可以使用自定义 Tuplizer 自定义 Hibernate 创建实体的方式。请参阅 hibernate 文档 第 4.5 章

您可以扩展PojoEntityTuplizer,并通过返回一个Instantiator实例来重写buildInstantiator(PersistentClass permanentClass)方法,该实例可以根据您的喜好构建实体。

You can customize the way Hibernate creates entities with a custom Tuplizer. See the hibernate documentation, chapter 4.5.

You can extend PojoEntityTuplizer, and override the buildInstantiator(PersistentClass persistentClass) method by returning an Instantiator instance which builds entities however you prefer.

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