I'm trying to make a simple app using Hibernate, but I'm getting this error and not sure why.
I'm using IntelliJ, made Maven Project and generated model from database:
this is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nemanjagajic</groupId>
<artifactId>FacultyJPA</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.15.Final</version>
</dependency>
</dependencies>
</project>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="FacultyJPAPersistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>model.Student</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/faculty"/>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="nemanja96"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.CharSet" value="utf8"/>
<property name="hibernate.connection.characterEncoding" value="utf8"/>
<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
basic JPAUtil:
package utils;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JPAUtil {
static EntityManagerFactory factory;
static {
factory = Persistence.createEntityManagerFactory("FacultyJPAPersistenceUnit");
}
public static EntityManager getEntityManager() {
return factory.createEntityManager();
}
}
and when I run it
public class Application {
public static void main(String[] args) {
Student student = new Student();
student.setId(1);
student.setName("John");
student.setLastName("Dee");
EntityManager em = JPAUtil.getEntityManager();
em.persist(student);
}
}
I'm getting the error above.
Not sure what I'm doing wrong and can't seem to configure simple project using hibernate whatever I try. If someone could tell me what is the problem or pass me the link of some tutorial creating simple project using hibernate that is not outdated and is working.