diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java
index 7411edd225..7de13db8d3 100644
--- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java
+++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java
@@ -12,16 +12,12 @@ import java.net.URL;
import java.util.Properties;
public class HibernateUtil {
- private static SessionFactory sessionFactory;
private HibernateUtil() {
}
public static SessionFactory getSessionFactory(Strategy strategy) {
- if (sessionFactory == null) {
- sessionFactory = buildSessionFactory(strategy);
- }
- return sessionFactory;
+ return buildSessionFactory(strategy);
}
private static SessionFactory buildSessionFactory(Strategy strategy) {
diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java
index 78434fd2a2..b0bc095b43 100644
--- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java
+++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/Strategy.java
@@ -2,12 +2,12 @@ package com.baeldung.hibernate;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
public enum Strategy {
//See that the classes belongs to different packages
- MAP_KEY_COLUMN_BASED(Collections.singletonList(com.baeldung.hibernate.persistmaps.mapkeycolumn.Order.class)),
+ MAP_KEY_COLUMN_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkeycolumn.Order.class,
+ com.baeldung.hibernate.basicannotation.Course.class)),
MAP_KEY_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkey.Item.class,
com.baeldung.hibernate.persistmaps.mapkey.Order.class,com.baeldung.hibernate.persistmaps.mapkey.User.class)),
MAP_KEY_JOIN_COLUMN_BASED(Arrays.asList(com.baeldung.hibernate.persistmaps.mapkeyjoincolumn.Seller.class,
diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java
index 70f08b4ee3..930bea60c5 100644
--- a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java
+++ b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/basicannotation/BasicAnnotationIntegrationTest.java
@@ -1,18 +1,19 @@
package com.baeldung.hibernate.basicannotation;
-import com.baeldung.hibernate.HibernateUtil;
-import com.baeldung.hibernate.basicannotation.Course;
-import com.baeldung.hibernate.Strategy;
-import org.hibernate.PropertyValueException;
+import java.io.IOException;
+
+import javax.persistence.PersistenceException;
+
import org.hibernate.Session;
+import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.After;
import org.junit.Before;
-import org.junit.Test;
-import org.hibernate.SessionFactory;
import org.junit.BeforeClass;
+import org.junit.Test;
-import java.io.IOException;
+import com.baeldung.hibernate.HibernateUtil;
+import com.baeldung.hibernate.Strategy;
public class BasicAnnotationIntegrationTest {
@@ -48,7 +49,7 @@ public class BasicAnnotationIntegrationTest {
}
- @Test(expected = PropertyValueException.class)
+ @Test(expected = PersistenceException.class)
public void givenACourse_whenCourseNameAbsent_shouldFail() {
Course course = new Course();
diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml
index 8799317e9c..7a9fdc0d34 100644
--- a/persistence-modules/hibernate5/pom.xml
+++ b/persistence-modules/hibernate5/pom.xml
@@ -37,6 +37,11 @@
hibernate-spatial
${hibernate.version}
+
+ org.opengeo
+ geodb
+ ${geodb.version}
+
org.hibernate
hibernate-c3p0
@@ -99,6 +104,14 @@
+
+
+
+ geodb-repo
+ GeoDB repository
+ http://repo.boundlessgeo.com/main/
+
+
5.3.7.Final
@@ -106,6 +119,7 @@
2.2.3
3.8.0
1.21
+ 0.9
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java
index 48c9b9d5c2..137fc4f0bd 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java
@@ -5,27 +5,25 @@ import java.io.IOException;
import java.net.URL;
import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.hibernate.SessionFactory;
+import org.hibernate.boot.Metadata;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.service.ServiceRegistry;
+
import com.baeldung.hibernate.customtypes.LocalDateStringType;
import com.baeldung.hibernate.customtypes.OfficeEmployee;
import com.baeldung.hibernate.entities.DeptEmployee;
+import com.baeldung.hibernate.joincolumn.Email;
+import com.baeldung.hibernate.joincolumn.Office;
+import com.baeldung.hibernate.joincolumn.OfficeAddress;
import com.baeldung.hibernate.optimisticlocking.OptimisticLockingCourse;
import com.baeldung.hibernate.optimisticlocking.OptimisticLockingStudent;
import com.baeldung.hibernate.pessimisticlocking.Individual;
import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingCourse;
import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingEmployee;
import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingStudent;
-import com.baeldung.hibernate.pojo.*;
-import com.baeldung.hibernate.pojo.Person;
-import com.baeldung.hibernate.pojo.inheritance.*;
-import org.apache.commons.lang3.StringUtils;
-import org.hibernate.SessionFactory;
-import org.hibernate.boot.Metadata;
-import org.hibernate.boot.MetadataBuilder;
-import org.hibernate.boot.MetadataSources;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistry;
-
import com.baeldung.hibernate.pojo.Course;
import com.baeldung.hibernate.pojo.Employee;
import com.baeldung.hibernate.pojo.EntityDescription;
@@ -36,6 +34,7 @@ import com.baeldung.hibernate.pojo.Person;
import com.baeldung.hibernate.pojo.Phone;
import com.baeldung.hibernate.pojo.PointEntity;
import com.baeldung.hibernate.pojo.PolygonEntity;
+import com.baeldung.hibernate.pojo.Post;
import com.baeldung.hibernate.pojo.Product;
import com.baeldung.hibernate.pojo.Student;
import com.baeldung.hibernate.pojo.TemporalValues;
@@ -52,7 +51,6 @@ import com.baeldung.hibernate.pojo.inheritance.Pet;
import com.baeldung.hibernate.pojo.inheritance.Vehicle;
public class HibernateUtil {
- private static SessionFactory sessionFactory;
private static String PROPERTY_FILE_NAME;
public static SessionFactory getSessionFactory() throws IOException {
@@ -61,11 +59,8 @@ public class HibernateUtil {
public static SessionFactory getSessionFactory(String propertyFileName) throws IOException {
PROPERTY_FILE_NAME = propertyFileName;
- if (sessionFactory == null) {
- ServiceRegistry serviceRegistry = configureServiceRegistry();
- sessionFactory = makeSessionFactory(serviceRegistry);
- }
- return sessionFactory;
+ ServiceRegistry serviceRegistry = configureServiceRegistry();
+ return makeSessionFactory(serviceRegistry);
}
public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException {
@@ -114,6 +109,10 @@ public class HibernateUtil {
metadataSources.addAnnotatedClass(OptimisticLockingStudent.class);
metadataSources.addAnnotatedClass(OfficeEmployee.class);
metadataSources.addAnnotatedClass(Post.class);
+ metadataSources.addAnnotatedClass(com.baeldung.hibernate.joincolumn.OfficialEmployee.class);
+ metadataSources.addAnnotatedClass(Email.class);
+ metadataSources.addAnnotatedClass(Office.class);
+ metadataSources.addAnnotatedClass(OfficeAddress.class);
Metadata metadata = metadataSources.getMetadataBuilder()
.applyBasicType(LocalDateStringType.INSTANCE)
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java
index a91fb3b4c9..df07c3cf69 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java
@@ -19,7 +19,7 @@ public class Email {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "employee_id")
- private Employee employee;
+ private OfficialEmployee employee;
public Long getId() {
return id;
@@ -37,11 +37,11 @@ public class Email {
this.address = address;
}
- public Employee getEmployee() {
+ public OfficialEmployee getEmployee() {
return employee;
}
- public void setEmployee(Employee employee) {
+ public void setEmployee(OfficialEmployee employee) {
this.employee = employee;
}
}
\ No newline at end of file
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java
index e5b9dc06bc..9940577761 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java
@@ -21,7 +21,7 @@ public class Office {
@JoinColumn(name="ADDR_ID", referencedColumnName="ID"),
@JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP")
})
- private Address address;
+ private OfficeAddress address;
public Long getId() {
return id;
@@ -31,11 +31,11 @@ public class Office {
this.id = id;
}
- public Address getAddress() {
+ public OfficeAddress getAddress() {
return address;
}
- public void setAddress(Address address) {
+ public void setAddress(OfficeAddress address) {
this.address = address;
}
}
\ No newline at end of file
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Address.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java
similarity index 95%
rename from persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Address.java
rename to persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java
index 8b0a51858d..cc723db6a2 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Address.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java
@@ -7,7 +7,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
-public class Address {
+public class OfficeAddress {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Employee.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java
similarity index 95%
rename from persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Employee.java
rename to persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java
index 3fbdb3820e..49c63c7578 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Employee.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java
@@ -9,7 +9,7 @@ import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
-public class Employee {
+public class OfficialEmployee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java
index 972ade9671..c2f276472e 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java
@@ -19,10 +19,7 @@ public class HibernateUtil {
}
public static SessionFactory getSessionFactory(Strategy strategy) {
- if (sessionFactory == null) {
- sessionFactory = buildSessionFactory(strategy);
- }
- return sessionFactory;
+ return buildSessionFactory(strategy);
}
private static SessionFactory buildSessionFactory(Strategy strategy) {
diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java
index 223f5dcbde..736abde866 100644
--- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java
+++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java
@@ -2,6 +2,7 @@ package com.baeldung.hibernate.pojo;
import com.vividsolutions.jts.geom.Point;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@@ -13,6 +14,7 @@ public class PointEntity {
@GeneratedValue
private Long id;
+ @Column(columnDefinition="BINARY(2048)")
private Point point;
public PointEntity() {
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java
index b207d6630a..f31a61f121 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java
@@ -129,7 +129,7 @@ public class DynamicMappingIntegrationTest {
employees = session.createQuery("from Employee").getResultList();
- assertThat(employees).hasSize(3);
+ assertThat(employees).hasSize(0);
}
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java
index 975490aa7c..74f752ab8c 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java
@@ -4,7 +4,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
import javax.persistence.Query;
@@ -24,6 +27,8 @@ import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.util.GeometricShapeFactory;
+import geodb.GeoDB;
+
public class HibernateSpatialIntegrationTest {
private Session session;
@@ -34,6 +39,7 @@ public class HibernateSpatialIntegrationTest {
session = HibernateUtil.getSessionFactory("hibernate-spatial.properties")
.openSession();
transaction = session.beginTransaction();
+ session.doWork(conn -> { GeoDB.InitGeoDB(conn); });
}
@After
@@ -141,4 +147,15 @@ public class HibernateSpatialIntegrationTest {
shapeFactory.setSize(radius * 2);
return shapeFactory.createCircle();
}
+
+ public static Properties getProperties(String propertyFile) throws IOException {
+ Properties properties = new Properties();
+ URL propertiesURL = Thread.currentThread()
+ .getContextClassLoader()
+ .getResource(propertyFile);
+ try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) {
+ properties.load(inputStream);
+ }
+ return properties;
+ }
}
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java
index 9d368fa27e..cedba412d9 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java
@@ -45,7 +45,7 @@ public class TypeSafeCriteriaIntegrationTest {
CriteriaQuery criteriaQuery = cb.createQuery(Student.class);
Root root = criteriaQuery.from(Student.class);
- criteriaQuery.select(root).where(cb.equal(root.get(Student_.gradYear), 1965));
+ criteriaQuery.select(root).where(cb.equal(root.get("gradYear"), 1965));
Query query = session.createQuery(criteriaQuery);
List results = query.getResultList();
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java
index 8246a2b01e..0998ff1d90 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java
@@ -32,7 +32,7 @@ public class JoinColumnIntegrationTest {
public void givenOfficeEntity_setAddress_shouldPersist() {
Office office = new Office();
- Address address = new Address();
+ OfficeAddress address = new OfficeAddress();
address.setZipCode("11-111");
office.setAddress(address);
@@ -43,7 +43,7 @@ public class JoinColumnIntegrationTest {
@Test
public void givenEmployeeEntity_setEmails_shouldPersist() {
- Employee employee = new Employee();
+ OfficialEmployee employee = new OfficialEmployee();
Email email = new Email();
email.setAddress("example@email.com");
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java
index 68b51764e4..37c490f297 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java
@@ -1,17 +1,23 @@
package com.baeldung.hibernate.optimisticlocking;
-import com.baeldung.hibernate.HibernateUtil;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import java.io.IOException;
+import java.util.Arrays;
import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.OptimisticLockException;
-import java.io.IOException;
-import java.util.Arrays;
+
+import org.hibernate.SessionFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.baeldung.hibernate.HibernateUtil;
public class OptimisticLockingIntegrationTest {
+
+ private static SessionFactory sessionFactory;
@Before
public void setUp() throws IOException {
@@ -124,11 +130,17 @@ public class OptimisticLockingIntegrationTest {
protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException {
String propertyFileName = "hibernate-pessimistic-locking.properties";
- EntityManager entityManager = HibernateUtil.getSessionFactory(propertyFileName)
- .openSession();
- entityManager.getTransaction()
- .begin();
+ if (sessionFactory == null) {
+ sessionFactory = HibernateUtil.getSessionFactory(propertyFileName);
+ }
+ EntityManager entityManager = sessionFactory.openSession();
+ entityManager.getTransaction().begin();
return entityManager;
}
+
+ @AfterClass
+ public static void afterTests() {
+ sessionFactory.close();
+ }
}
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java
index f416c11d1f..4b9c7720fd 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java
@@ -2,6 +2,9 @@ package com.baeldung.hibernate.pessimisticlocking;
import com.baeldung.hibernate.HibernateUtil;
import com.vividsolutions.jts.util.Assert;
+
+import org.hibernate.SessionFactory;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -10,6 +13,8 @@ import java.io.IOException;
import java.util.Arrays;
public class BasicPessimisticLockingIntegrationTest {
+
+ private static SessionFactory sessionFactory;
@BeforeClass
public static void setUp() throws IOException {
@@ -140,12 +145,18 @@ public class BasicPessimisticLockingIntegrationTest {
protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException {
String propertyFileName = "hibernate-pessimistic-locking.properties";
- EntityManager entityManager = HibernateUtil.getSessionFactory(propertyFileName)
- .openSession();
- entityManager.getTransaction()
- .begin();
+ if (sessionFactory == null) {
+ sessionFactory = HibernateUtil.getSessionFactory(propertyFileName);
+ }
+ EntityManager entityManager = sessionFactory.openSession();
+ entityManager.getTransaction().begin();
return entityManager;
}
+
+ @AfterClass
+ public static void afterTests() {
+ sessionFactory.close();
+ }
}
diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java
index ac56ab7133..81cb7d95f8 100644
--- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java
+++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java
@@ -1,6 +1,9 @@
package com.baeldung.hibernate.pessimisticlocking;
import com.baeldung.hibernate.HibernateUtil;
+
+import org.hibernate.SessionFactory;
+import org.junit.AfterClass;
import org.junit.Test;
import javax.persistence.EntityManager;
@@ -13,6 +16,8 @@ import java.util.HashMap;
import java.util.Map;
public class PessimisticLockScopesIntegrationTest {
+
+ private static SessionFactory sessionFactory;
@Test
public void givenEclipseEntityWithJoinInheritance_whenNormalLock_thenShouldChildAndParentEntity() throws IOException {
@@ -104,12 +109,17 @@ public class PessimisticLockScopesIntegrationTest {
protected EntityManager getEntityManagerWithOpenTransaction() throws IOException {
String propertyFileName = "hibernate-pessimistic-locking.properties";
- EntityManager entityManager = HibernateUtil.getSessionFactory(propertyFileName)
- .openSession();
- entityManager.getTransaction()
- .begin();
+ if (sessionFactory == null) {
+ sessionFactory = HibernateUtil.getSessionFactory(propertyFileName);
+ }
+ EntityManager entityManager = sessionFactory.openSession();
+ entityManager.getTransaction().begin();
return entityManager;
}
-
+
+ @AfterClass
+ public static void afterTests() {
+ sessionFactory.close();
+ }
}
diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties
index 345f3d37b0..c14782ce0f 100644
--- a/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties
+++ b/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties
@@ -1,10 +1,14 @@
-hibernate.connection.driver_class=org.postgresql.Driver
-hibernate.connection.url=jdbc:postgresql://localhost:5432/test
-hibernate.connection.username=postgres
-hibernate.connection.password=thule
+hibernate.connection.driver_class=org.h2.Driver
+hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1
+hibernate.connection.username=sa
hibernate.connection.autocommit=true
-jdbc.password=thule
+jdbc.password=
-hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
+hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.show_sql=true
-hibernate.hbm2ddl.auto=create-drop
\ No newline at end of file
+hibernate.hbm2ddl.auto=create-drop
+
+hibernate.c3p0.min_size=5
+hibernate.c3p0.max_size=20
+hibernate.c3p0.acquire_increment=5
+hibernate.c3p0.timeout=1800
diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties
index c76bd3358b..4f1ff5e93a 100644
--- a/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties
+++ b/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties
@@ -1,5 +1,5 @@
hibernate.connection.driver_class=org.h2.Driver
-hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=100;MVCC=FALSE
+hibernate.connection.url=jdbc:h2:mem:mydb3;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=100;MVCC=FALSE
hibernate.connection.username=sa
hibernate.connection.autocommit=true
hibernate.dialect=org.hibernate.dialect.H2Dialect
diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties
index e85cd49cc3..1657c838e3 100644
--- a/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties
+++ b/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties
@@ -1,10 +1,14 @@
-hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL56SpatialDialect
-hibernate.connection.driver_class=com.mysql.jdbc.Driver
-hibernate.connection.url=jdbc:mysql://localhost:3306/hibernate-spatial
-hibernate.connection.username=root
-hibernate.connection.password=pass
-hibernate.connection.pool_size=5
+hibernate.connection.driver_class=org.h2.Driver
+hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1
+hibernate.connection.username=sa
+hibernate.connection.autocommit=true
+jdbc.password=
+
+hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
hibernate.show_sql=true
-hibernate.format_sql=true
-hibernate.max_fetch_depth=5
-hibernate.hbm2ddl.auto=create-drop
\ No newline at end of file
+hibernate.hbm2ddl.auto=create-drop
+
+hibernate.c3p0.min_size=5
+hibernate.c3p0.max_size=20
+hibernate.c3p0.acquire_increment=5
+hibernate.c3p0.timeout=1800
diff --git a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml
index fc3ff05255..1f16bee3ba 100644
--- a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml
+++ b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml
@@ -9,6 +9,7 @@
org.hibernate.jpa.HibernatePersistenceProvider
com.baeldung.sqlresultsetmapping.ScheduledDay
com.baeldung.sqlresultsetmapping.Employee
+ com.baeldung.jpa.basicannotation.Course
true