From 2db3ce26436dd6a735f89e9e133c0aecb3ecd3dd Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 24 Apr 2020 11:06:07 +0100 Subject: [PATCH] HHH-10956 an exception has to thrown when the composite key is an association and its value is null --- .../tuple/entity/AbstractEntityTuplizer.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java index 53fa2d9d12..61066326d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java @@ -39,6 +39,7 @@ import org.hibernate.proxy.ProxyFactory; import org.hibernate.tuple.IdentifierProperty; import org.hibernate.tuple.Instantiator; import org.hibernate.type.AssociationType; +import org.hibernate.type.BasicType; import org.hibernate.type.ComponentType; import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; @@ -371,24 +372,23 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer { final Type[] copierSubTypes = mappedIdentifierType.getSubtypes(); final int length = subTypes.length; for ( int i = 0; i < length; i++ ) { + final Type subType = subTypes[i]; if ( propertyValues[i] == null ) { - try { - final String name = names[i]; - final Property p = ((Component) identifier).getProperty(name); - final SimpleValue v = (SimpleValue) p.getValue(); - if ( v.getIdentifierGenerator() == null ) { - throw new NullPointerException("No IdentifierGenerator found for property "+name); - } + if ( subType.isAssociationType() ) { + throw new HibernateException( "No part of a composite identifier may be null" ); } - catch (Throwable t) { - throw new HibernateException( "No part of a composite identifier may be null", t ); + final String name = names[i]; + final Property p = ( (Component) identifier ).getProperty( name ); + final SimpleValue v = (SimpleValue) p.getValue(); + if ( v.getIdentifierGenerator() == null ) { + throw new HibernateException( "No part of a composite identifier may be null" ); } } //JPA 2 @MapsId + @IdClass points to the pk of the entity - if ( subTypes[i].isAssociationType() && !copierSubTypes[i].isAssociationType() ) { + if ( subType.isAssociationType() && !copierSubTypes[i].isAssociationType() ) { propertyValues[i] = determineEntityId( propertyValues[i], - (AssociationType) subTypes[i], + (AssociationType) subType, session, sessionFactory );