From 33125197842b8d9c85618708a728329088961849 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 18 Jan 2022 15:26:30 +0100 Subject: [PATCH] Use IdentifiableType.hasSingleIdAttribute() to detect IdClass presence to obtain IdClass attributes. We now use IdentifiableType.hasSingleIdAttribute() to detect whether a type should have an IdClass. hasSingleIdAttribute is defined to return false if an IdClass is being used. It could also return false in case multiple identifier attributes are in place (composite Id) which is a bit of a grey area. At least we avoid using Hibernate-specific API. Original pull request #2412 See #2330 Closes #2391 --- .../data/jpa/provider/PersistenceProvider.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/provider/PersistenceProvider.java b/src/main/java/org/springframework/data/jpa/provider/PersistenceProvider.java index 4f9323c7df..23e0d9ea0e 100644 --- a/src/main/java/org/springframework/data/jpa/provider/PersistenceProvider.java +++ b/src/main/java/org/springframework/data/jpa/provider/PersistenceProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ import org.eclipse.persistence.queries.ScrollableCursor; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; -import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor; import org.hibernate.proxy.HibernateProxy; + import org.springframework.data.util.CloseableIterator; import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -103,9 +103,7 @@ public Object getIdentifierFrom(Object entity) { */ @Override public Set> getIdClassAttributes(IdentifiableType type) { - return type instanceof IdentifiableTypeDescriptor && ((IdentifiableTypeDescriptor) type).hasIdClass() - ? super.getIdClassAttributes(type) - : Collections.emptySet(); + return type.hasSingleIdAttribute() ? Collections.emptySet() : super.getIdClassAttributes(type); } /*