Summary of Several Exceptions and Solutions Encountered in hibernate Testing
- 2021-07-10 19:47:34
- OfStack
Today, I used hibernate 3.6. 5 to configure jar lib myself, and I encountered several exceptions during the test as follows:
1.java.lang.NoSuchFieldError: INSTANCE
Resolution: Delete hibernate-annotations. jar.2.java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector
Resolution: Delete hibernate-commons-annotations. jar.3.org.hibernate.HibernateException: No CurrentSessionContext configured!
Solution: Add hibernate-jpa-2. 0-api-1. 0.0. Final. jar4.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. There is no configuration of CurrentSessionContext.
Solution: In an environment where Hibernate is integrated (e.g. Jboss), add in the session-factory section of hibernate. cfg. xml:
Xml code:
<property name="current_session_context_class">jta</property>
In environments that do not integrate Hibernate (for example, stand-alone applications using JDBC), add the following in the session-factory section of hibernate. cfg. xml:
Xml code:
<property name="current_session_context_class">thread</property>
Test run, ok!
Summarize