Hibernate problem handling one

In the process of learning Hibernate according to "Lightweight Java EE Enterprise Application Practice 4th Edition", the following errors were encountered, and the solutions were specially recorded.

1.org/hibernate/service/ServiceRegistry : Unsupported major.minor version 52.0

The example in the tutorial uses hibernate 4.3.5, I use hibernate 5.2.12 in the learning process, and eclipse jre is jdk 1.7.

jdk1.7 does not support the latest version 5.2.12 of hibernate, in the hibernate official website

5.2 series

so required, Compatibility

Java 8+
JPA 2.1

jdk 1.7 can only support hibernate 5.1 series, to solve this problem, either use jdk1.8, or use hibernate 5.1 corresponding to jdk 1.7

 

2.org.hibernate.MappingException: Unknown entity

According to the example code in the tutorial is written like this:

Configuration conf=new Configuration().configure();

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();

SessionFactory sf=conf.buildSessionFactory(serviceRegistry);

Session sess=sf.openSession();

 

Transaction tx=sess.beginTransaction();

An error is reported when the object is generated: org.hibernate.MappingException: Unknown entity

Looking for information, it is still a version problem. After hibernate 5.0, the above code needs to be modified as follows:

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();

SessionFactory sf=new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();

Session sess=sf.openSession();

 

Transaction tx=sess.beginTransaction();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326232957&siteId=291194637