java 如何强制 Hibernate 3.3 或 3.5 使用 CGLib 而不是 Javassist?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2330373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to force Hibernate 3.3 or 3.5 to use CGLib instead of Javassist?
提问by mshafrir
Is it still possible to force Hibernate 3.3 or 3.5 to use CGLib instead of Javassist? In my properties file, I set
是否仍然可以强制 Hibernate 3.3 或 3.5 使用 CGLib 而不是 Javassist?在我的属性文件中,我设置
hibernate.bytecode.provider = cglib
But this doesn't seem to do it. Any thoughts?
但这似乎并没有做到。有什么想法吗?
回答by Pascal Thivent
It seems some people didn't read my answer correctly so I'll rephrase: your hibernate.propertieslooks correct, the property is well defined, it should work. So, sorry for the question but is CGlib on the classpath?
似乎有些人没有正确阅读我的答案,所以我会改写:您的hibernate.properties外观正确,属性定义明确,应该可以使用。所以,很抱歉这个问题,但是 CGlib 在类路径上吗?
Update:Just tested and it works for me. Here is the output I get at initialization time:
更新:刚刚测试过,它对我有用。这是我在初始化时得到的输出:
15 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1
18 [main] INFO org.hibernate.cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false, hibernate.bytecode.provider=cglib}
20 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
PS: Note that CGLIB support has been deprecatedrecently (this doesn't mean you won't be able to use CGLIB but the integration it not maintained anymore).
PS:请注意,最近不推荐使用 CGLIB 支持(这并不意味着您将无法使用 CGLIB,而是不再维护它的集成)。
回答by Martin
Yeah, also put
是的,也放
hibernate.properties
into some source folder and remember to have the hibermate-cglib-repack in dependencies:
进入某个源文件夹并记住在依赖项中有 hibermate-cglib-repack:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-cglib-repack</artifactId>
<version>2.1_3</version>
</dependency>
回答by iirekm
Remember that CGLIB library is not developed for about 4 years. You should do everything however to make your code working with Javassist, which is still actively maintained.
请记住,CGLIB 库的开发时间约为 4 年。但是,您应该尽一切努力使您的代码与 Javassist 一起工作,Javassist 仍在积极维护中。

