时间:2021-05-14 10:37:38 | 栏目:JAVA代码 | 点击:次
今天使用hibernate3.6.5自己配置jar lib,在测试时遇到了几个异常如下:
1.java.lang.NoSuchFieldError: INSTANCE
2.java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector
3.org.hibernate.HibernateException: No CurrentSessionContext configured!
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)
5.没有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!
总结