Skip to content

Commit 204da85

Browse files
committed
HHH-19829 - Restrict use of MultiFindOptions to the findMultiple operations
Signed-off-by: Jan Schatteman <[email protected]>
1 parent acceac6 commit 204da85

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

hibernate-core/src/main/java/org/hibernate/MultiFindOption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
/**
1111
* Simple marker interface for FindOptions which can be applied to multiple id loading.
1212
*/
13-
interface MultiFindOption extends FindOption {
13+
public interface MultiFindOption extends FindOption {
1414
}

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,9 @@ else if ( option instanceof EnabledFetchProfile enabledFetchProfile ) {
23002300
else if ( option instanceof ReadOnlyMode ) {
23012301
loadAccess.withReadOnly( option == ReadOnlyMode.READ_ONLY );
23022302
}
2303+
else if ( option instanceof MultiFindOption multiFindOption ) {
2304+
throw new IllegalArgumentException( "Option '" + multiFindOption + "' can only be used in 'findMultiple()'" );
2305+
}
23032306
}
23042307
if ( lockOptions.getLockMode().isPessimistic() ) {
23052308
if ( lockOptions.getTimeOut() == WAIT_FOREVER_MILLI ) {

hibernate-core/src/test/java/org/hibernate/orm/test/dynamicmap/FindOperationTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
*/
55
package org.hibernate.orm.test.dynamicmap;
66

7+
import org.hibernate.IncludeRemovals;
8+
import org.hibernate.OrderedReturn;
79
import org.hibernate.ReadOnlyMode;
10+
import org.hibernate.SessionChecking;
811
import org.hibernate.graph.RootGraph;
912
import org.hibernate.testing.orm.junit.DomainModel;
1013
import org.hibernate.testing.orm.junit.SessionFactory;
@@ -17,6 +20,7 @@
1720
import java.util.Map;
1821

1922
import static org.assertj.core.api.Assertions.assertThat;
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
2024

2125
/**
2226
* @author Steve Ebersole
@@ -58,6 +62,15 @@ void testFindWithOptions(SessionFactoryScope factoryScope) {
5862
} );
5963
}
6064

65+
@Test
66+
void testFindWithIllegalOptions(SessionFactoryScope factoryScope) {
67+
factoryScope.inTransaction( (session) -> {
68+
assertThrows( IllegalArgumentException.class, () ->session.find( "artist", 1, SessionChecking.ENABLED ) );
69+
assertThrows( IllegalArgumentException.class, () ->session.find( "artist", 1, OrderedReturn.ORDERED ) );
70+
assertThrows( IllegalArgumentException.class, () ->session.find( "artist", 1, IncludeRemovals.INCLUDE ) );
71+
} );
72+
}
73+
6174
@Test
6275
void testFindWithGraph(SessionFactoryScope factoryScope) {
6376
factoryScope.inTransaction( (session) -> {

0 commit comments

Comments
 (0)