Skip to content

Commit

Permalink
Use IdentifiableType.hasSingleIdAttribute() to detect IdClass presenc…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
mp911de authored and schauder committed Jan 21, 2022
1 parent 1a3ba4c commit 680cc4d
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -103,9 +103,7 @@ public Object getIdentifierFrom(Object entity) {
*/
@Override
public <T> Set<SingularAttribute<? super T, ?>> getIdClassAttributes(IdentifiableType<T> type) {
return type instanceof IdentifiableTypeDescriptor && ((IdentifiableTypeDescriptor<T>) type).hasIdClass()
? super.getIdClassAttributes(type)
: Collections.emptySet();
return type.hasSingleIdAttribute() ? Collections.emptySet() : super.getIdClassAttributes(type);
}

/*
Expand Down

0 comments on commit 680cc4d

Please sign in to comment.