這個問題我學Hibernate的時候遇到了,各種方法都試過,兩天才查出了,不過學的不是很深。感覺是因為表間聯系才出的問題。
最近又有人來問我這個問題,他是其他的都能查出來,但是排序查詢就出這個異常,但也通過我的方法解決了。所以我也整理了
一下發表出來,希望可以幫助到大家。
解決方法:1.在配置這個類的配置文件中many-to-one標簽中添加fetch=“join” 這個還會報異常,不過可以查詢出來了
2.在配置這個類的配置文件中many-to-one標簽中添加lazy=“false”,不延遲加載,就沒有問題了
異常名:
11:00:26.288 [main] ERROR org.hibernate.proxy.pojo.javassist.JavassistProxyFactory - HHH000142: Javassist Enhancement failed: com.zking.domain.Customer
java.lang.ClassCastException: com.zking.domain.Customer_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
Junit顯示:
org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: com.zking.domain.Customer
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:130)
...
Caused by: java.lang.ClassCastException: com.zking.domain.Customer_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:123)
... 49 more
本人對Hibernate了解不深,可能說的不太對,歡迎在評論區指點下,謝謝!