【hibernate框架4】hibernate遇到的幾個異常解決

 今天使用hibernate3.6.5自己配置jar lib,在測試時遇到了幾個異常如下:


1.java.lang.NoSuchFieldError: INSTANCE


      解決:刪除hibernate-annotations.jar。


2.java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector


      解決:刪除hibernate-commons-annotations.jar。


3.org.hibernate.HibernateException: No CurrentSessionContext configured!


      解決:添加hibernate-jpa-2.0-api-1.0.0.Final.jar


4.org.hibernate.HibernateException: No TransactionManagerLookup specified


   at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:81)
   at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:687)
   at com.cvv.service.UserManager.exists(UserManager.java:16)


      沒有CurrentSessionContext的配置。


      解決:在集成Hibernate的環境下(例如Jboss),要在hibernate.cfg.xml中session-factory段加入: 


Xml代碼 :  
      <property name="current_session_context_class">jta</property>
在不集成Hibernate的環境下(例如使用JDBC的獨立應用程序),在hibernate.cfg.xml中session-factory段加入:


Xml代碼 :


      <property name="current_session_context_class">thread</property>


測試運行,ok!
--------------------- 
作者:光仔December 
來源:CSDN 
原文:https://blog.csdn.net/acmman/article/details/43116271 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章