JAVA-23344 Fix failing tests in hibernate-annotations (#14468)
This commit is contained in:
parent
4215e52c4d
commit
f82330cd1b
|
@ -79,7 +79,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.hypersistence</groupId>
|
<groupId>io.hypersistence</groupId>
|
||||||
<artifactId>hypersistence-utils-hibernate-60</artifactId>
|
<artifactId>hypersistence-utils-hibernate-60</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>${hypersistance-utils-hibernate-60.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@
|
||||||
<hibernate-core.version>6.1.7.Final</hibernate-core.version>
|
<hibernate-core.version>6.1.7.Final</hibernate-core.version>
|
||||||
<maven.deploy.skip>true</maven.deploy.skip>
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
|
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
|
||||||
|
<hypersistance-utils-hibernate-60.version>3.3.1</hypersistance-utils-hibernate-60.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,6 +1,8 @@
|
||||||
package com.baeldung.hibernate.primarykeyjoincolumn;
|
package com.baeldung.hibernate.primarykeyjoincolumn;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
@ -9,6 +11,7 @@ import jakarta.persistence.Table;
|
||||||
public class Department {
|
public class Department {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
@ -3,14 +3,16 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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"
|
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="com.baeldung.movie_catalog">
|
<persistence-unit name="com.baeldung.department_person">
|
||||||
<description>Hibernate EntityManager Demo</description>
|
<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>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<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="hibernate.hbm2ddl.auto" value="update"/>
|
||||||
<property name="jakarta.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/moviecatalog"/>
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:departmentperson"/>
|
||||||
<property name="jakarta.persistence.jdbc.user" value="root"/>
|
<property name="jakarta.persistence.jdbc.user" value="root"/>
|
||||||
<property name="jakarta.persistence.jdbc.password" value="root"/>
|
<property name="jakarta.persistence.jdbc.password" value="root"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
package com.baeldung.hibernate.primarykeyjoincolumn;
|
package com.baeldung.hibernate.primarykeyjoincolumn;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import jakarta.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
public class PrimaryKeyJoinColumnIntegrationTest {
|
class PrimaryKeyJoinColumnIntegrationTest {
|
||||||
|
|
||||||
private static EntityManagerFactory emf;
|
private static EntityManagerFactory emf;
|
||||||
|
|
||||||
private EntityManager em;
|
private static EntityManager em;
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void setup() {
|
public static void setup() {
|
||||||
emf = Persistence.createEntityManagerFactory("com.baeldung.movie_catalog");
|
emf = Persistence.createEntityManagerFactory("com.baeldung.department_person");
|
||||||
em = emf.createEntityManager();
|
em = emf.createEntityManager();
|
||||||
em.getTransaction()
|
em.getTransaction()
|
||||||
.begin();
|
.begin();
|
||||||
|
@ -34,19 +34,18 @@ public class PrimaryKeyJoinColumnIntegrationTest {
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterAll
|
||||||
public void teardown() {
|
public static void teardown() {
|
||||||
em.close();
|
em.close();
|
||||||
emf.close();
|
emf.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPersonEntity_getDepartment_shouldExist() {
|
void givenPersonEntity_getDepartment_shouldExist() {
|
||||||
Person person = em.find(Person.class, 1L);
|
Person person = em.find(Person.class, 1L);
|
||||||
assertNotNull(person);
|
assertNotNull(person);
|
||||||
assertEquals("John Doe", person.getName());
|
assertEquals("John Doe", person.getName());
|
||||||
assertNotNull(person.getDepartment());
|
assertNotNull(person.getDepartment());
|
||||||
assertEquals("IT", person.getDepartment()
|
assertEquals("IT", person.getDepartment().getName());
|
||||||
.getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue