Skip to content

Commit 2af1dc1

Browse files
gavinkingDavideD
authored andcommitted
[#2800] remove() is documented to throw IllegalArgumentException
not HibernateException
1 parent dd182ad commit 2af1dc1

File tree

8 files changed

+13
-71
lines changed

8 files changed

+13
-71
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveDeleteEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private CompletionStage<Void> fetchAndDelete(DeleteEvent event, DeleteContext tr
195195
: !source.contains( objectEvent );
196196
if ( detached ) {
197197
// Hibernate Reactive doesn't support detached instances in remove()
198-
throw new IllegalArgumentException( "unmanaged instance passed to remove()" );
198+
throw new IllegalArgumentException( "Unmanaged instance passed to remove()" );
199199
}
200200

201201
//Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveLockEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public CompletionStage<Void> reactiveOnLock(LockEvent event) throws HibernateExc
7373
: !source.contains( event.getObject() );
7474
if ( detached ) {
7575
// Hibernate Reactive doesn't support detached instances in refresh()
76-
throw new IllegalArgumentException( "unmanaged instance passed to refresh()" );
76+
throw new IllegalArgumentException( "Unmanaged instance passed to refresh()" );
7777
}
7878

7979

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveExceptionConverter.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionFactoryImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.hibernate.boot.spi.MetadataImplementor;
1010
import org.hibernate.boot.spi.SessionFactoryOptions;
1111
import org.hibernate.internal.SessionFactoryImpl;
12-
import org.hibernate.query.spi.QueryEngine;
1312
import org.hibernate.reactive.boot.spi.ReactiveMetadataImplementor;
1413
import org.hibernate.reactive.mutiny.Mutiny;
1514
import org.hibernate.reactive.mutiny.impl.MutinySessionFactoryImpl;
@@ -29,11 +28,6 @@ public ReactiveSessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFact
2928
super( new ReactiveMetadataImplementor( bootMetamodel ), options, bootstrapContext );
3029
}
3130

32-
@Override
33-
public QueryEngine getQueryEngine() {
34-
return super.getQueryEngine();
35-
}
36-
3731
@Override
3832
public <T> T unwrap(Class<T> type) {
3933
if ( type.isAssignableFrom( Stage.SessionFactory.class ) ) {

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.hibernate.engine.spi.EffectiveEntityGraph;
3737
import org.hibernate.engine.spi.EntityEntry;
3838
import org.hibernate.engine.spi.EntityKey;
39-
import org.hibernate.engine.spi.ExceptionConverter;
4039
import org.hibernate.engine.spi.PersistenceContext;
4140
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
4241
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
@@ -167,9 +166,6 @@ public class ReactiveSessionImpl extends SessionImpl implements ReactiveSession,
167166
private ReactiveConnection reactiveConnection;
168167
private final Thread associatedWorkThread;
169168

170-
//Lazily initialized
171-
private transient ExceptionConverter exceptionConverter;
172-
173169
public ReactiveSessionImpl(SessionFactoryImpl delegate, SessionCreationOptions options, ReactiveConnection connection) {
174170
super( delegate, options );
175171
InternalStateAssertions.assertUseOnEventLoop();
@@ -1128,14 +1124,6 @@ private CompletionStage<Void> doFlush() {
11281124
} );
11291125
}
11301126

1131-
@Override
1132-
public ExceptionConverter getExceptionConverter() {
1133-
if ( exceptionConverter == null ) {
1134-
exceptionConverter = new ReactiveExceptionConverter( this );
1135-
}
1136-
return exceptionConverter;
1137-
}
1138-
11391127
@Override
11401128
public CompletionStage<Void> reactiveRefresh(Object entity, LockOptions lockOptions) {
11411129
checkOpen();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MutinySessionTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Objects;
1111
import java.util.concurrent.atomic.AtomicInteger;
1212

13-
import org.hibernate.HibernateException;
1413
import org.hibernate.LockMode;
1514
import org.hibernate.exception.ConstraintViolationException;
1615
import org.hibernate.reactive.mutiny.Mutiny;
@@ -301,13 +300,10 @@ context, populateDB()
301300
.chain( () -> selectNameFromId( 5 ) )
302301
.invoke( name -> assertThat( name ).isNotNull() )
303302
.chain( this::openMutinySession )
304-
.chain( session -> assertThrown(
305-
HibernateException.class,
306-
session.remove( new GuineaPig( 5, "Aloi" ) )
307-
) )
303+
.chain( session -> assertThrown( IllegalArgumentException.class, session
304+
.remove( new GuineaPig( 5, "Aloi" ) ) ) )
308305
.invoke( e -> assertThat( e )
309-
.hasMessageContaining( "unmanaged instance passed to remove" )
310-
)
306+
.hasMessageContaining( "Unmanaged instance passed to remove" ) )
311307
);
312308
}
313309

hibernate-reactive-core/src/test/java/org/hibernate/reactive/ReactiveSessionTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.concurrent.CompletionException;
1111
import java.util.concurrent.CompletionStage;
1212

13-
import org.hibernate.HibernateException;
1413
import org.hibernate.LockMode;
1514
import org.hibernate.reactive.common.AffectedEntities;
1615
import org.hibernate.reactive.mutiny.Mutiny;
@@ -725,11 +724,11 @@ public void reactiveRemoveTransientEntity(VertxTestContext context) {
725724
.thenCompose( v -> selectNameFromId( 5 ) )
726725
.thenAccept( result -> assertThat( result ).isNotNull() )
727726
.thenCompose( v -> openSession() )
728-
.thenCompose( session -> assertThrown( HibernateException.class, session.remove( new GuineaPig( 5, "Aloi" ) ) )
729-
)
727+
.thenCompose( session -> assertThrown( IllegalArgumentException.class, session
728+
.remove( new GuineaPig( 5, "Aloi" ) ) ) )
730729
.thenAccept( t -> assertThat( t )
731-
.hasCauseInstanceOf( IllegalArgumentException.class )
732-
.hasMessageContaining( "unmanaged instance" )
730+
.isInstanceOf( IllegalArgumentException.class )
731+
.hasMessageContaining( "Unmanaged instance" )
733732
)
734733
);
735734
}

integration-tests/hibernate-validator-postgres-it/src/test/java/org/hibernate/reactive/it/quarkus/qe/database/DatabaseHibernateReactiveTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.concurrent.TimeUnit;
1111

1212

13-
import org.hibernate.HibernateException;
1413

1514
import org.junit.jupiter.api.Test;
1615

@@ -43,29 +42,27 @@ public static <U extends Throwable> Uni<U> assertThrown(Class<U> expectedExcepti
4342

4443
@Test
4544
public void nameIsTooLong(VertxTestContext context) {
46-
test( context, assertThrown( HibernateException.class, getMutinySessionFactory()
45+
test( context, assertThrown( ConstraintViolationException.class, getMutinySessionFactory()
4746
.withTransaction( s -> {
4847
Author author = new Author();
4948
author.setName( "A very long long long long name ... " );
5049
return s.persist( author );
5150
} ) )
52-
.invoke( he -> assertThat( he.getCause() )
53-
.isInstanceOf( ConstraintViolationException.class )
51+
.invoke( he -> assertThat( he )
5452
.hasMessageContaining( "size must be between" )
5553
)
5654
);
5755
}
5856

5957
@Test
6058
public void nameIsNull(VertxTestContext context) {
61-
test( context, assertThrown( HibernateException.class, getMutinySessionFactory()
59+
test( context, assertThrown( ConstraintViolationException.class, getMutinySessionFactory()
6260
.withTransaction( s -> {
6361
Author author = new Author();
6462
author.setName( null );
6563
return s.persist( author );
6664
} ) )
67-
.invoke( he -> assertThat( he.getCause() )
68-
.isInstanceOf( ConstraintViolationException.class )
65+
.invoke( he -> assertThat( he )
6966
.hasMessageContaining( "must not be null" )
7067
)
7168
);

0 commit comments

Comments
 (0)