From dca2bcfda5fa23a0228a71edc49016368962639f Mon Sep 17 00:00:00 2001 From: Barry LaFond Date: Wed, 28 Jun 2023 11:46:31 -0500 Subject: [PATCH] [#1504] align merge tests with new ORM merge tests --- .../reactive/EagerUniqueKeyTest.java | 12 +++--- .../hibernate/reactive/LazyUniqueKeyTest.java | 39 +++++++++++++++---- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerUniqueKeyTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerUniqueKeyTest.java index c84a5a7e48..c79b1aa985 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerUniqueKeyTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerUniqueKeyTest.java @@ -12,7 +12,6 @@ import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import jakarta.persistence.CascadeType; @@ -73,18 +72,17 @@ public void testMergeDetached(VertxTestContext context) { ) ) ); } - @Disabled // see https://github.com/hibernate/hibernate-reactive/issues/1504 @Test public void testMergeReference(VertxTestContext context) { Bar bar = new Bar( "unique3" ); test( context, getSessionFactory() .withTransaction( session -> session.persist( bar ) ) .thenCompose( i -> getSessionFactory() - .withTransaction( session -> session - .merge( new Foo( session.getReference( Bar.class, bar.getId() ) ) ) ) ) - .thenCompose( result -> getSessionFactory().withTransaction( session -> session.fetch( result.getBar() ) - .thenAccept( b -> assertEquals( "unique3", b.getKey() ) ) - ) ) + .withTransaction( session -> { + Bar reference = session.getReference( Bar.class, bar.getId() ); + return session.merge( new Foo( reference ) ); + } ) ) + .thenAccept( merged -> assertEquals( merged.getBar().getKey(), bar.getKey() ) ) ); } diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/LazyUniqueKeyTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/LazyUniqueKeyTest.java index 9833a6b36f..73d602396b 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/LazyUniqueKeyTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/LazyUniqueKeyTest.java @@ -13,7 +13,6 @@ import org.hibernate.annotations.FetchMode; import org.hibernate.reactive.testing.DBSelectionExtension; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -80,17 +79,19 @@ public void testMergeDetached(VertxTestContext context) { ) ) ); } - @Disabled // see https://github.com/hibernate/hibernate-reactive/issues/1504 @Test public void testMergeReference(VertxTestContext context) { Bar bar = new Bar( "unique3" ); test( context, getSessionFactory() .withTransaction( session -> session.persist( bar ) ) .thenCompose( i -> getSessionFactory() - .withTransaction( session-> session.merge( new Foo( session.getReference( Bar.class, bar.id ) ) ) ) + .withTransaction( session-> { + Bar reference = session.getReference( Bar.class, bar.id ); + return session.merge( new Foo( reference ) ); + } ) ) - .thenCompose( result -> getSessionFactory() - .withTransaction( session-> session.fetch( result.bar ) + .thenCompose( merged -> getSessionFactory() + .withTransaction( session-> session.fetch( merged.bar ) .thenAccept( b -> assertEquals( "unique3", b.key ) ) ) ) ); } @@ -121,13 +122,29 @@ static class Foo { Foo() { } - @GeneratedValue @Id + @GeneratedValue long id; @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) @Fetch(FetchMode.SELECT) @JoinColumn(name = "bar_key", referencedColumnName = "nat_key") Bar bar; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Bar getBar() { + return bar; + } + + public void setBar(Bar bar) { + this.bar = bar; + } } @Entity(name = "Bar") @@ -139,12 +156,20 @@ static class Bar implements Serializable { Bar() { } - @GeneratedValue @Id + @GeneratedValue long id; @Column(name = "nat_key", unique = true) String key; + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + public String getKey() { return key; }