Set correct key type if !referenceToPrimaryKey

This commit is contained in:
Fabio Massimo Ercoli 2021-12-22 21:09:29 +01:00 committed by Christian Beikov
parent 3ea5a066ed
commit 91a720772f
2 changed files with 11 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.hibernate.sql.results.graph.entity.AbstractEntityInitializer;
import org.hibernate.sql.results.graph.entity.EntityInitializer;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.type.Type;
/**
* @author Andrea Boriero
@ -113,11 +114,19 @@ public class EntityDelayedFetchInitializer extends AbstractFetchParentAccess imp
else {
if ( selectByUniqueKey ) {
final String uniqueKeyPropertyName = referencedModelPart.getBidirectionalAttributeName();
final Type uniqueKeyPropertyType = ( referencedModelPart.getReferencedPropertyName() == null ) ?
concreteDescriptor.getIdentifierType() :
session.getFactory()
.getReferencedPropertyType(
concreteDescriptor.getEntityName(),
uniqueKeyPropertyName
);
final EntityUniqueKey euk = new EntityUniqueKey(
concreteDescriptor.getEntityName(),
uniqueKeyPropertyName,
identifier,
concreteDescriptor.getIdentifierType(),
uniqueKeyPropertyType,
session.getFactory()
);
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.uniquekey;
package org.hibernate.orm.test.uniquekey;
import java.io.Serializable;
import jakarta.persistence.Entity;