JAVA-23344 Fix failing tests in hibernate-annotations (#14468)

This commit is contained in:
timis1 2023-07-27 19:27:17 +03:00 committed by GitHub
parent 4215e52c4d
commit f82330cd1b
4 changed files with 25 additions and 20 deletions

View File

@ -79,7 +79,7 @@
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-60</artifactId>
<version>3.3.1</version>
<version>${hypersistance-utils-hibernate-60.version}</version>
</dependency>
</dependencies>
@ -90,6 +90,7 @@
<hibernate-core.version>6.1.7.Final</hibernate-core.version>
<maven.deploy.skip>true</maven.deploy.skip>
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
<hypersistance-utils-hibernate-60.version>3.3.1</hypersistance-utils-hibernate-60.version>
</properties>
</project>

View File

@ -1,6 +1,8 @@
package com.baeldung.hibernate.primarykeyjoincolumn;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@ -9,6 +11,7 @@ import jakarta.persistence.Table;
public class Department {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;

View File

@ -3,14 +3,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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="com.baeldung.movie_catalog">
<persistence-unit name="com.baeldung.department_person">
<description>Hibernate EntityManager Demo</description>
<class>com.baeldung.hibernate.primarykeyjoincolumn.Person</class>
<class>com.baeldung.hibernate.primarykeyjoincolumn.Department</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="jakarta.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/moviecatalog"/>
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:departmentperson"/>
<property name="jakarta.persistence.jdbc.user" value="root"/>
<property name="jakarta.persistence.jdbc.password" value="root"/>
</properties>

View File

@ -1,25 +1,25 @@
package com.baeldung.hibernate.primarykeyjoincolumn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
public class PrimaryKeyJoinColumnIntegrationTest {
class PrimaryKeyJoinColumnIntegrationTest {
private static EntityManagerFactory emf;
private EntityManager em;
private static EntityManager em;
@Before
public void setup() {
emf = Persistence.createEntityManagerFactory("com.baeldung.movie_catalog");
@BeforeAll
public static void setup() {
emf = Persistence.createEntityManagerFactory("com.baeldung.department_person");
em = emf.createEntityManager();
em.getTransaction()
.begin();
@ -34,19 +34,18 @@ public class PrimaryKeyJoinColumnIntegrationTest {
.commit();
}
@After
public void teardown() {
@AfterAll
public static void teardown() {
em.close();
emf.close();
}
@Test
public void givenPersonEntity_getDepartment_shouldExist() {
void givenPersonEntity_getDepartment_shouldExist() {
Person person = em.find(Person.class, 1L);
assertNotNull(person);
assertEquals("John Doe", person.getName());
assertNotNull(person.getDepartment());
assertEquals("IT", person.getDepartment()
.getName());
assertEquals("IT", person.getDepartment().getName());
}
}