Skip to content

Commit 5ded8ea

Browse files
committed
include the id of the collection in an LIE
1 parent 27f3ea6 commit 5ded8ea

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -657,19 +657,21 @@ private void throwLazyInitializationExceptionIfNotConnected() {
657657
}
658658

659659
private void throwLazyInitializationException(String message) {
660-
throwLazyInitializationException( role, message);
661-
}
662-
663-
private static void throwLazyInitializationException(String role, String message) {
664-
throw new LazyInitializationException(
665-
String.format( "Cannot lazily initialize collection%s (%s)",
666-
role == null ? "" : " of role '" + role + "'", message )
667-
);
660+
final var error = new StringBuilder( "Cannot lazily initialize collection" );
661+
if ( role != null ) {
662+
error.append( " of role '" ).append( role ).append( "'" );
663+
}
664+
if ( key != null ) {
665+
error.append( " with key '" ).append( key ).append( "'" );
666+
}
667+
error.append( " (" ).append( message ).append( ")" );
668+
throw new LazyInitializationException( error.toString() );
668669
}
669670

670671
public static void checkPersister(PersistentCollection<?> collection, CollectionPersister persister) {
671672
if ( !collection.wasInitialized() && persister == null ) {
672-
throwLazyInitializationException( null, "collection is being removed" );
673+
throw new LazyInitializationException( "Cannot lazily initialize collection"
674+
+ " (collection is being removed)" );
673675
}
674676
}
675677

0 commit comments

Comments
 (0)