Skip to content

Commit

Permalink
[hibernate#1504] align merge tests with new ORM merge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blafond committed Jun 28, 2023
1 parent b411fef commit dca2bcf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() ) )
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ) )
) ) );
}
Expand Down Expand Up @@ -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")
Expand All @@ -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;
}
Expand Down

0 comments on commit dca2bcf

Please sign in to comment.