昨天在写entity类时,在运行jetty时出错
16:01:39,782 ERROR JavassistLazyInitializer:166 - HHH000142: Javassist Enhancement failed: com.highrace.car.model.CarLicence
java.lang.RuntimeException: duplicate method: getHandler in com.highrace.car.model.CarLicence_$$_javassist_30
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)
......
Caused by: javassist.bytecode.DuplicateMemberException: duplicate method: getHandler in com.highrace.car.model.CarLicence_$$_javassist_30
......
我反反复复的检查entity类,发现并没有配置错误,最后错误定位到javassist包下面应该有getHandler与我的getHandler方法冲突
在网上查找方法
第一种,将默认的javassist改成cglib,
1、导入cglib-nobep-2.2
2、在hibernate.properties文件中加入
hibernate.bytecode.provider=cglib
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<!-- 由于我的hibernate是与spring集成的所以没有hibernate.properties文件
只能在这加这两条配置 -->
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
<prop key="hibernate.bytecode.provider">cglib</prop>
</props>
</property>
http://stackoverflow.com/questions/2269185/duplicate-method-error-when-using-hibernate-javassist-gilead
第一种没成功。
第二种,经过我的反复查找,网上有人说这是javassist的一个bug,说后续版本可能会解决这个bug,于是我添加了下面的版本替换之前的版本,问题解决了。
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
https://hibernate.atlassian.net/browse/HHH-5731