HHH-16023 Check fetchable declaring type when not found in persister

This commit is contained in:
Marco Belladelli 2023-01-17 15:49:31 +01:00 committed by Christian Beikov
parent 64b3855c73
commit 7cd6d0422f
2 changed files with 23 additions and 4 deletions

View File

@ -1828,7 +1828,7 @@ public abstract class AbstractEntityPersister
return fetches.build();
}
private boolean isSelectable(FetchParent fetchParent, Fetchable fetchable) {
protected boolean isSelectable(FetchParent fetchParent, Fetchable fetchable) {
if ( fetchParent instanceof EmbeddableResultGraphNode ) {
return true;
}
@ -1836,9 +1836,24 @@ public abstract class AbstractEntityPersister
final AttributeMapping attributeMapping = fetchable.asAttributeMapping();
if ( attributeMapping != null ) {
final int propertyNumber = attributeMapping.getStateArrayPosition();
// final int tableNumber = getSubclassPropertyTableNumber( propertyNumber );
// return !isSubclassTableSequentialSelect( tableNumber ) && propertySelectable[propertyNumber];
return propertySelectable[propertyNumber];
if ( propertyNumber < propertySelectable.length ) {
return propertySelectable[propertyNumber];
}
else {
final ManagedMappingType declaringType = attributeMapping.getDeclaringType();
// try to check select-ability from the declaring type
if ( declaringType != this ) {
assert declaringType instanceof AbstractEntityPersister;
final AbstractEntityPersister subPersister = (AbstractEntityPersister) declaringType;
return subPersister.propertySelectable[propertyNumber];
}
else {
throw new IllegalArgumentException(
"Unrecognized fetchable [" + fetchable.getFetchableName() + "] at index "
+ propertyNumber + " for entity [" + getEntityName() + "]"
);
}
}
}
else {
return true;

View File

@ -8,8 +8,11 @@ package org.hibernate.orm.test.jpa.ql;
import java.util.List;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
@ -38,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
})
@SessionFactory
@JiraKey("HHH-16023")
@RequiresDialect(H2Dialect.class)
public class NamedNativeQueryWithGenericsTest {
@Test
public void testNamedNativeQuery(SessionFactoryScope scope) {