关于在使用Hibernate时出现javassist.bytecode.DuplicateMemberException的问题

一、背景

技术架构:基于AppFuse的SSH架构。

Spring 3.1.3

Struts2 2.3.15.1

Hibernate 4.1.8

二、问题解析

在某一entity类中增加几个属性后,启动jetty运行应用时,启动过程中出错并抛出异常。

2014-09-25 14:02:21.578 ERROR JavassistLazyInitializer.getProxyFactory(166) | HHH000142: Javassist Enhancement failed: myapp.model.process.ProcessLog
java.lang.RuntimeException: duplicate method: getHandler in myapp.model.process.ProcessLog_$$_javassist_26
	at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:510)
	at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:487)
	at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:423)
	at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:395)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:163)
	......
Caused by: javassist.bytecode.DuplicateMemberException: duplicate method: getHandler in myapp.model.process.ProcessLog_$$_javassist_26
	at javassist.bytecode.ClassFile.testExistingMethod(ClassFile.java:665)
	at javassist.bytecode.ClassFile.addMethod(ClassFile.java:641)
	at javassist.util.proxy.ProxyFactory.addGetter(ProxyFactory.java:899)
	at javassist.util.proxy.ProxyFactory.make(ProxyFactory.java:718)
	at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:498)
	... 96 more
2014-09-25 14:02:21.593 WARN  PojoEntityTuplizer.buildProxyFactory(233) | HHH000305: Could not create proxy factory for:myapp.model.process.ProcessLog
org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: myapp.model.process.ProcessLog
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:167)
	at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.java:66)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:221)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:212)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:82)
	......
Caused by: java.lang.RuntimeException: duplicate method: getHandler in myapp.model.process.ProcessLog_$$_javassist_26
	at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:510)
	at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:487)
	at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:423)
	at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:395)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:163)
	... 92 more
Caused by: javassist.bytecode.DuplicateMemberException: duplicate method: getHandler in myapp.model.process.ProcessLog_$$_javassist_26
	at javassist.bytecode.ClassFile.testExistingMethod(ClassFile.java:665)
	at javassist.bytecode.ClassFile.addMethod(ClassFile.java:641)
	at javassist.util.proxy.ProxyFactory.addGetter(ProxyFactory.java:899)
	at javassist.util.proxy.ProxyFactory.make(ProxyFactory.java:718)
	at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:498)
	... 96 more
异常显示我新增的属性  handler 的get方法  getHandler 重复,修改方法名为 getHandlerA后,启动正常。

仔细检查该 entity 类及其父类后,并无发现存在冲突的方法,故初步判断方法getHandler应该是和某依赖类的方法在命名上冲突了。

通过搜索引擎,在网上发现了已有开发人员遇到同类问题,并断定为 hibernate4.1.8 所以依赖的 javassist-3.15.0-GA 的一个bug

关于在使用Hibernate时出现javassist.bytecode.DuplicateMemberException的问题_第1张图片

三、解决方法

JBossDeveloper上显示,该问题已在 3.16.0-GA 版本中得到修复,故在POM中添加3.16.0-GA或更高版本的依赖、并排除低版本的依赖即可。如:


    org.javassist
    javassist
    3.16.1-GA
升级Javassist版本后,启动jetty运行应用正常。

四、相关链接

感谢 oschina 的 王鹏1989 分享的日志《hibernate4.2.1默认集成javassist-3.15.0-GA包的一个bug问题》

Javassist Enhancement fails when JPA Entity has an attribute named "handler"

ProxyObject#setHandler interferes with business methods of the same name

你可能感兴趣的:(Java,J2EE)