-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-18976 Avoid usage of Array.newInstance #9589
Changes from all commits
3741a62
c50c8be
b0fcfab
06cbf3b
d7551cb
d9d2fbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.internal.build; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
|
||
@Retention( RetentionPolicy.CLASS ) | ||
@Target({ TYPE, METHOD, CONSTRUCTOR }) | ||
public @interface AllowReflection { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
import org.hibernate.sql.exec.spi.JdbcSelectExecutor; | ||
import org.hibernate.type.descriptor.java.JavaType; | ||
|
||
import java.lang.reflect.Array; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
@@ -39,14 +38,12 @@ | |
public abstract class AbstractMultiIdEntityLoader<T> implements MultiIdEntityLoader<T> { | ||
private final EntityMappingType entityDescriptor; | ||
private final SessionFactoryImplementor sessionFactory; | ||
private final EntityIdentifierMapping identifierMapping; | ||
protected final Object[] idArray; | ||
protected final EntityIdentifierMapping identifierMapping; | ||
|
||
public AbstractMultiIdEntityLoader(EntityMappingType entityDescriptor, SessionFactoryImplementor sessionFactory) { | ||
this.entityDescriptor = entityDescriptor; | ||
this.sessionFactory = sessionFactory; | ||
identifierMapping = getLoadable().getIdentifierMapping(); | ||
idArray = (Object[]) Array.newInstance( identifierMapping.getJavaType().getJavaTypeClass(), 0 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the main problem affecting Quarkus, FWIW. |
||
} | ||
|
||
protected EntityMappingType getEntityDescriptor() { | ||
|
@@ -301,10 +298,13 @@ else if ( unresolvedIds.size() == ids.length ) { | |
} | ||
else { | ||
// we need to load only some the ids | ||
return unresolvedIds.toArray( idArray ); | ||
return toIdArray( unresolvedIds ); | ||
} | ||
} | ||
|
||
// Depending on the implementation, a specific subtype of Object[] (e.g. Integer[]) may be needed. | ||
protected abstract Object[] toIdArray(List<Object> ids); | ||
|
||
private boolean isIdCoercionEnabled() { | ||
return !getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is still done, but deeper within the
multiLoad
call, and only when necessary (seeMultiIdEntityLoaderArrayParam
).