I got an exception when I use hibernate in Maven. The hibernate version is 5.1.0.Final.
The exception is:
Here is my project structure:
Here is my Entity class ABC:
package com;
import javax.persistence.*;
@Entity
@Table(name = "abc_inf")
public class ABC {
@Id@GeneratedValue
private Integer id;
private String name;
public ABC() {
}
setters and getters omitted
}
Here is my main class:
package com;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class Main {
public static void main(String[] args) {
Configuration conf = new Configuration().configure();
ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();
SessionFactory sf = conf.buildSessionFactory(sr);
Session session = sf.openSession();
ABC abc = new ABC();
abc.setName("abc");
session.save(abc);
session.flush();
session.close();
sf.close();
}
}
Here is my hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
mysql connection and properties settings omitted
<mapping class="com.ABC"/>
</session-factory>
</hibernate-configuration>