From c021287296f0b31a4deb42eef621e61cdb2db783 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Mon, 18 Sep 2023 16:11:34 +0200 Subject: [PATCH] HHH-17205 Avoid select by unique key with no referenced property --- .../metamodel/mapping/internal/ToOneAttributeMapping.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index e4160d9da9..1cc94e09e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -1725,6 +1725,9 @@ public class ToOneAttributeMapping } private boolean isSelectByUniqueKey(ForeignKeyDescriptor.Nature side) { + if ( referencedPropertyName == null ) { + return false; + } if ( side == ForeignKeyDescriptor.Nature.KEY ) { // case 1.2 return !foreignKeyDescriptor.getNavigableRole()