hibernate4.2.1默認集成javassist-3.15.0-GA包的一個bug問題

昨天在寫entity類時,在運行jetty時出錯
java

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方法衝突spring

在網上查找方法sql

第一種,將默認的javassist改爲cglib,ide

    一、導入cglib-nobep-2.2.net

    二、在hibernate.properties文件中加入hibernate

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/2330373/how-to-force-hibernate-3-3-or-3-5-to-use-cglib-instead-of-javassistcode

http://stackoverflow.com/questions/2269185/duplicate-method-error-when-using-hibernate-javassist-gileadorm

第一種沒成功。get

第二種,通過個人反覆查找,網上有人說這是javassist的一個bug,說後續版本可能會解決這個bug,因而我添加了下面的版本替換以前的版本,問題解決了。it

<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.18.2-GA</version>
</dependency>

https://hibernate.atlassian.net/browse/HHH-5731

相關文章
相關標籤/搜索