用于 Hibernate 映射的自定义类加载器
有谁知道拦截 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用自定义
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 thebuildInstantiator(PersistentClass persistentClass)
method by returning anInstantiator
instance which builds entities however you prefer.