From 520538b23d9761bd2008ad19a7abcf122eb623c6 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 1221f5b5a0..dcef955a30 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 @@ -1728,6 +1728,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()