HHH-17290 Add test for issue
This commit is contained in:
parent
f309a88552
commit
04f18cc6a2
|
@ -0,0 +1,128 @@
|
|||
package org.hibernate.orm.test.embeddable;
|
||||
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.Embedded;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
@Jpa(
|
||||
annotatedClasses = {
|
||||
NullEmbeddableTest.EntityA.class
|
||||
}
|
||||
)
|
||||
@JiraKey("HHH-17290")
|
||||
public class NullEmbeddableTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.createQuery( "delete from EntityA" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = new EntityA( "1", null );
|
||||
entityManager.persist( entityA );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = entityManager.find( EntityA.class, "1" );
|
||||
assertThat( entityA.materialCost ).isNull();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = new EntityA( "1", null );
|
||||
entityManager.persist( entityA );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = entityManager.find( EntityA.class, "1" );
|
||||
entityA.materialCost = null;
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = entityManager.find( EntityA.class, "1" );
|
||||
assertThat( entityA.materialCost ).isNull();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMerge(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = new EntityA( "1", new Cost( 2, "USD" ) );
|
||||
entityManager.persist( entityA );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = new EntityA( "1", null );
|
||||
entityManager.merge( entityA );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA entityA = entityManager.find( EntityA.class, "1" );
|
||||
assertThat( entityA.materialCost ).isNull();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name = "EntityA")
|
||||
public static class EntityA {
|
||||
@Id
|
||||
String id;
|
||||
|
||||
@Embedded
|
||||
Cost materialCost;
|
||||
|
||||
public EntityA() {
|
||||
}
|
||||
|
||||
public EntityA(String id, Cost materialCost) {
|
||||
this.id = id;
|
||||
this.materialCost = materialCost;
|
||||
}
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
public static class Cost {
|
||||
int amount;
|
||||
String currency;
|
||||
|
||||
public Cost() {
|
||||
}
|
||||
|
||||
public Cost(Integer amount, String currency) {
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
# See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
#
|
||||
appender.stdout.type=Console
|
||||
appender.stdout.name=STDOUT
|
||||
appender.stdout.layout.type=PatternLayout
|
||||
appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
rootLogger.level=info
|
||||
rootLogger.appenderRef.stdout.ref=STDOUT
|
||||
|
||||
logger.test.name=org.hibernate.test
|
||||
logger.test.level=info
|
||||
|
||||
# SQL Logging - HHH-6833
|
||||
logger.sql.name=org.hibernate.SQL
|
||||
logger.sql.level=debug
|
Loading…
Reference in New Issue