diff --git a/README.md b/README.md index 509706206..73fb60f72 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Hibernate Reactive has been tested with: - CockroachDB v24 - MS SQL Server 2022 - Oracle 23 -- [Hibernate ORM][] 7.0.0.CR1 +- [Hibernate ORM][] 7.0.0.Final - [Vert.x Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg-client/java/) 4.5.14 - [Vert.x Reactive MySQL Client](https://vertx.io/docs/vertx-mysql-client/java/) 4.5.14 - [Vert.x Reactive Db2 Client](https://vertx.io/docs/vertx-db2-client/java/) 4.5.14 diff --git a/gradle.properties b/gradle.properties index 3da2482ba..78784fc69 100644 --- a/gradle.properties +++ b/gradle.properties @@ -35,12 +35,12 @@ org.gradle.java.installations.auto-download=false #enableMavenLocalRepo = true # The default Hibernate ORM version (override using `-PhibernateOrmVersion=the.version.you.want`) -hibernateOrmVersion = 7.0.0.CR2 +hibernateOrmVersion = 7.0.0.Final # Override default Hibernate ORM Gradle plugin version # Using the stable version because I don't know how to configure the build to download the snapshot version from # a remote repository -#hibernateOrmGradlePluginVersion = 7.0.0.CR1 +#hibernateOrmGradlePluginVersion = 7.0.0.Final # If set to true, skip Hibernate ORM version parsing (default is true, if set to null) # this is required when using intervals or weird versions or the build will fail diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveAbstractMultiIdEntityLoader.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveAbstractMultiIdEntityLoader.java index 71ae6e7e7..9b7c16395 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveAbstractMultiIdEntityLoader.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveAbstractMultiIdEntityLoader.java @@ -62,4 +62,7 @@ public final CompletionStage> reactiveLoad(K[] ids, MultiIdLoadOptio protected abstract CompletionStage> performUnorderedMultiLoad(K[] ids, MultiIdLoadOptions loadOptions, SharedSessionContractImplementor session); + protected boolean isIdCoercionEnabled() { + return !getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled(); + } } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java index 612e5ad16..ef81c828e 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderArrayParam.java @@ -90,7 +90,7 @@ protected CompletionStage> performOrderedMultiLoad( ); } - final boolean coerce = !getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled(); + final boolean coerce = isIdCoercionEnabled(); final LockOptions lockOptions = ( loadOptions.getLockOptions() == null ) ? new LockOptions( LockMode.NONE ) : loadOptions.getLockOptions(); @@ -312,7 +312,7 @@ protected final K[] processResolvableEntities( return ids; } - final boolean coerce = !getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled(); + final boolean coerce = isIdCoercionEnabled(); boolean foundAnyResolvedEntities = false; List nonResolvedIds = null; diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java index 743078403..5661c3493 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveMultiIdEntityLoaderStandard.java @@ -103,7 +103,7 @@ protected CompletionStage> performOrderedMultiLoad( final List idsInBatch = new ArrayList<>(); final List elementPositionsLoadedByBatch = new ArrayList<>(); - final boolean coerce = !getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled(); + final boolean coerce = isIdCoercionEnabled(); return loop( 0, ids.length, i -> { final Object id = coerce ? getEntityDescriptor().getIdentifierMapping().getJavaType().coerce( ids[i], session ) @@ -311,7 +311,7 @@ protected CompletionStage> performUnorderedMultiLoad( boolean foundAnyManagedEntities = false; final List nonManagedIds = new ArrayList<>(); - final boolean coerce = !getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled(); + final boolean coerce = isIdCoercionEnabled(); for ( Object o : ids ) { final Object id = coerce ? getEntityDescriptor().getIdentifierMapping().getJavaType().coerce( o, session ) diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java index d03822be6..795b565ff 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java @@ -382,7 +382,7 @@ public ReactiveQuery createReactiveQuery(CriteriaQuery criteriaQuery) return createReactiveCriteriaQuery( selectStatement, criteriaQuery.getResultType() ); } catch (RuntimeException e) { - if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { + if ( getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { markForRollbackOnly(); } throw getExceptionConverter().convert( e ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java index 1c8be13e6..d67cc2018 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java @@ -979,7 +979,7 @@ public ReactiveQuery createReactiveQuery(CriteriaQuery criteriaQuery) return createReactiveCriteriaQuery( selectStatement, criteriaQuery.getResultType() ); } catch (RuntimeException e) { - if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { + if ( getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isJpaTransactionComplianceEnabled() ) { markForRollbackOnly(); } throw getExceptionConverter().convert( e ); diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/JoinedSubclassInheritanceTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/JoinedSubclassInheritanceTest.java index 2b0e3f9c6..ab64e1925 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/JoinedSubclassInheritanceTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/JoinedSubclassInheritanceTest.java @@ -5,11 +5,6 @@ */ package org.hibernate.reactive; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Objects; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -26,12 +21,13 @@ import jakarta.persistence.Table; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Objects; import static java.util.concurrent.TimeUnit.MINUTES; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @Timeout(value = 10, timeUnit = MINUTES) @@ -56,9 +52,8 @@ public void testRootClassViaAssociation(VertxTestContext context) { .thenCompose( v -> openSession() ) .thenCompose( s2 -> s2.find( Author.class, author.getId() ) ) .thenAccept( auth -> { - assertNotNull( auth ); - assertEquals( author, auth ); - assertEquals( book.getTitle(), auth.getBook().getTitle() ); + assertThat( auth ).isEqualTo( author ); + assertThat( auth.getBook().getTitle() ).isEqualTo( book.getTitle() ); } ) ) ); @@ -77,9 +72,8 @@ public void testSubclassViaAssociation(VertxTestContext context) { .thenCompose( v -> s.flush() ) .thenCompose( v -> s.find( Author.class, author.getId() ) ) .thenAccept( auth -> { - assertNotNull( auth ); - assertEquals( author, auth ); - assertEquals( book.getTitle(), auth.getBook().getTitle() ); + assertThat( auth ).isEqualTo( author ); + assertThat( auth.getBook().getTitle() ).isEqualTo( book.getTitle() ); } ) ) ); @@ -87,7 +81,6 @@ public void testSubclassViaAssociation(VertxTestContext context) { @Test public void testRootClassViaFind(VertxTestContext context) { - final Book novel = new Book( 6, "The Boy, The Mole, The Fox and The Horse", new Date()); final Author author = new Author( "Charlie Mackesy", novel ); @@ -99,9 +92,8 @@ public void testRootClassViaFind(VertxTestContext context) { .thenCompose( v -> openSession() .thenCompose( s -> s.find(Book.class, 6) ) ) .thenAccept(book -> { - assertNotNull(book); - assertFalse(book instanceof SpellBook); - assertEquals(book.getTitle(), "The Boy, The Mole, The Fox and The Horse"); + assertThat( book ).isNotInstanceOf( SpellBook.class ); + assertThat( book.getTitle() ).isEqualTo( "The Boy, The Mole, The Fox and The Horse" ); })); } @@ -117,35 +109,41 @@ public void testSubclassViaFind(VertxTestContext context) { .thenCompose( v -> s.flush() ) ) .thenCompose( v -> openSession().thenCompose( s -> s.find(Book.class, 6) ) ) .thenAccept(book -> { - assertNotNull(book); - assertTrue(book instanceof SpellBook); - assertEquals(book.getTitle(), "Necronomicon"); + assertThat( book ).isInstanceOf( SpellBook.class ); + assertThat( book.getTitle() ).isEqualTo( "Necronomicon" ); })); } @Test public void testQueryUpdate(VertxTestContext context) { final SpellBook spells = new SpellBook( 6, "Necronomicon", true, new Date() ); -// final Author author = new Author( "Abdul Alhazred", spells ); - test( context, + test( + context, openSession() - .thenCompose( s -> s.persist(spells).thenCompose( v -> s.flush() ) ) + .thenCompose( s -> s.persist( spells ).thenCompose( v -> s.flush() ) ) .thenCompose( vv -> openSession() - .thenCompose( s -> s.withTransaction( t -> s.createMutationQuery("update SpellBook set title='x' where forbidden=false").executeUpdate() ) - .thenCompose( v -> s.withTransaction( t -> s.createMutationQuery("update SpellBook set forbidden=false where title='Necronomicon'").executeUpdate() ) ) - .thenCompose( v -> s.withTransaction( t -> s.createMutationQuery("update Book set title=title||' II' where title='Necronomicon'").executeUpdate() ) ) - .thenCompose( v -> s.find(Book.class, 6) ) + .thenCompose( s -> s.withTransaction( t -> s + .createMutationQuery( "update SpellBook set title='x' where forbidden=false" ) + .executeUpdate() ) + .thenCompose( v -> s.withTransaction( t -> s + .createMutationQuery( "update SpellBook set forbidden=false where title='Necronomicon'" ) + .executeUpdate() ) ) + .thenCompose( v -> s.withTransaction( t -> s + .createMutationQuery( "update Book set title=title||' II' where title='Necronomicon'" ) + .executeUpdate() ) ) + .thenCompose( v -> s.find( Book.class, 6 ) ) .thenAccept( book -> { - assertNotNull(book); - assertTrue(book instanceof SpellBook); - assertEquals(book.getTitle(), "Necronomicon II"); + assertThat( book ).isInstanceOf( SpellBook.class ); + assertThat( book.getTitle() ).isEqualTo( "Necronomicon II" ); } ) - ) ) + ) ) .thenCompose( vv -> openSession() - .thenCompose( s -> s.withTransaction( t -> s.createMutationQuery("delete Book where title='Necronomicon II'").executeUpdate() ) ) + .thenCompose( s -> s.withTransaction( t -> s + .createMutationQuery( "delete Book where title='Necronomicon II'" ) + .executeUpdate() ) ) .thenCompose( v -> openSession() ) - .thenCompose( s -> s.find(Book.class, 6) ) + .thenCompose( s -> s.find( Book.class, 6 ) ) .thenAccept( Assertions::assertNull ) ) ); @@ -154,7 +152,6 @@ public void testQueryUpdate(VertxTestContext context) { @Test public void testQueryUpdateWithParameters(VertxTestContext context) { final SpellBook spells = new SpellBook( 6, "Necronomicon", true, new Date() ); -// final Author author = new Author( "Abdul Alhazred", spells ); test( context, openSession() @@ -174,11 +171,9 @@ public void testQueryUpdateWithParameters(VertxTestContext context) { .thenCompose( v -> openSession() .thenCompose( s -> s.find( Book.class, 6) ) .thenAccept( book -> { - assertNotNull(book); - assertTrue(book instanceof SpellBook); - assertEquals(book.getTitle(), "Necronomicon II"); - } - ) + assertThat( book ).isInstanceOf( SpellBook.class ); + assertThat( book.getTitle() ).isEqualTo( "Necronomicon II" ); + } ) ) .thenCompose( v -> openSession() .thenCompose( s -> s.withTransaction( t -> s.createMutationQuery("delete Book where title=:tit") @@ -207,6 +202,11 @@ public SpellBook(Integer id, String title, boolean forbidden, Date published) { public boolean getForbidden() { return forbidden; } + + @Override + public String toString() { + return "SpellBook{" + super.toString() + ",forbidden=" + forbidden + '}'; + } } @Entity(name="Book") @@ -268,6 +268,11 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash( title ); } + + @Override + public String toString() { + return id + ", " + title + ", " + published; + } } @Entity(name = "Author")