Updates Hibernate to version 5.2.3

With this version:
	- There is no need to declare your entities in <class> elements in persistence.xml.
	- You can open and close an entitymanagerfactory in each test class without hangs
          between test classes.
parent ed1ba041
......@@ -26,7 +26,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version>
<version>5.2.3.Final</version>
</dependency>
<!-- Bean Validation (hibernate implementation) -->
......@@ -38,7 +38,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
<version>5.2.3.Final</version>
</dependency>
<dependency> <!-- requiered by hibernate-validator -->
<groupId>javax.el</groupId>
......
......@@ -3,10 +3,6 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="si-database" transaction-type="RESOURCE_LOCAL">
<class>dgpena.siexample.persistence.Department</class>
<class>dgpena.siexample.persistence.Employee</class>
<class>dgpena.siexample.persistence.Project</class>
<class>dgpena.siexample.persistence.ProjectAssignment</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="siuser" />
......
......@@ -15,19 +15,12 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class DepartmentsTest extends SQLBasedTest {
private static EntityManagerFactory emf;
@BeforeClass
public static void setUpEntityManagerFactory() {
emf = Persistence.createEntityManagerFactory("si-database");
}
@Test
public void testAddNewDepartment() throws Exception {
......
......@@ -10,18 +10,12 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class EmployeesTest extends SQLBasedTest {
private static EntityManagerFactory emf;
@BeforeClass
public static void setUpEntityManagerFactory() {
emf = Persistence.createEntityManagerFactory("si-database");
}
@Test
public void testAddNewEmployee() throws SQLException {
// insert a department previously with JDBC
......
......@@ -6,13 +6,20 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
public class SQLBasedTest {
private static final String DB_URL = "jdbc:mysql://localhost:3306/si";
private static final String DB_USER = "siuser";
private static final String DB_PASS = "sipass";
protected static Connection jdbcConnection = createConnection();
private static Connection createConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
......@@ -29,4 +36,20 @@ public class SQLBasedTest {
return rs.getInt(1);
}
// EntityManagerFactory management
protected static EntityManagerFactory emf;
@BeforeClass
public static void setUpEntityManagerFactory() {
emf = Persistence.createEntityManagerFactory("si-database");
}
@AfterClass
public static void closeEntityManagerFactory() throws SQLException {
if (emf != null && emf.isOpen()) {
emf.close();
}
}
}
......@@ -3,11 +3,6 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="si-database" transaction-type="RESOURCE_LOCAL">
<class>dgpena.siexample.persistence.Department</class>
<class>dgpena.siexample.persistence.Employee</class>
<class>dgpena.siexample.persistence.Project</class>
<class>dgpena.siexample.persistence.ProjectAssignment</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="siuser" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment