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 @@ ...@@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId> <artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version> <version>5.2.3.Final</version>
</dependency> </dependency>
<!-- Bean Validation (hibernate implementation) --> <!-- Bean Validation (hibernate implementation) -->
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId> <artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version> <version>5.2.3.Final</version>
</dependency> </dependency>
<dependency> <!-- requiered by hibernate-validator --> <dependency> <!-- requiered by hibernate-validator -->
<groupId>javax.el</groupId> <groupId>javax.el</groupId>
......
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0"> version="2.0">
<persistence-unit name="si-database" transaction-type="RESOURCE_LOCAL"> <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> <properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="siuser" /> <property name="javax.persistence.jdbc.user" value="siuser" />
......
...@@ -15,19 +15,12 @@ import javax.persistence.EntityManager; ...@@ -15,19 +15,12 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence; import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
public class DepartmentsTest extends SQLBasedTest { public class DepartmentsTest extends SQLBasedTest {
private static EntityManagerFactory emf;
@BeforeClass
public static void setUpEntityManagerFactory() {
emf = Persistence.createEntityManagerFactory("si-database");
}
@Test @Test
public void testAddNewDepartment() throws Exception { public void testAddNewDepartment() throws Exception {
......
...@@ -10,18 +10,12 @@ import javax.persistence.EntityManager; ...@@ -10,18 +10,12 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence; import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
public class EmployeesTest extends SQLBasedTest { public class EmployeesTest extends SQLBasedTest {
private static EntityManagerFactory emf;
@BeforeClass
public static void setUpEntityManagerFactory() {
emf = Persistence.createEntityManagerFactory("si-database");
}
@Test @Test
public void testAddNewEmployee() throws SQLException { public void testAddNewEmployee() throws SQLException {
// insert a department previously with JDBC // insert a department previously with JDBC
......
...@@ -6,13 +6,20 @@ import java.sql.ResultSet; ...@@ -6,13 +6,20 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
public class SQLBasedTest { public class SQLBasedTest {
private static final String DB_URL = "jdbc:mysql://localhost:3306/si"; private static final String DB_URL = "jdbc:mysql://localhost:3306/si";
private static final String DB_USER = "siuser"; private static final String DB_USER = "siuser";
private static final String DB_PASS = "sipass"; private static final String DB_PASS = "sipass";
protected static Connection jdbcConnection = createConnection(); protected static Connection jdbcConnection = createConnection();
private static Connection createConnection() { private static Connection createConnection() {
try { try {
Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver");
...@@ -29,4 +36,20 @@ public class SQLBasedTest { ...@@ -29,4 +36,20 @@ public class SQLBasedTest {
return rs.getInt(1); 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 @@ ...@@ -3,11 +3,6 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0"> version="2.0">
<persistence-unit name="si-database" transaction-type="RESOURCE_LOCAL"> <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> <properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="siuser" /> <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