Revert HHH-16616 backport

This commit is contained in:
Marco Belladelli 2023-08-28 20:53:18 +02:00
parent 0175edef61
commit 840ec40f02
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
7 changed files with 9 additions and 193 deletions

View File

@ -300,9 +300,6 @@ public class OneToManyPersister extends AbstractCollectionPersister {
SqlAstCreationState astCreationState) {
super.applyWhereFragments( predicateConsumer, alias, tableGroup, astCreationState );
if ( !astCreationState.supportsEntityNameUsage() ) {
// We only need to apply discriminator for loads, since queries with joined
// inheritance subtypes are already filtered by the entity name usage logic
getElementPersisterInternal().applyDiscriminator(
predicateConsumer,
alias,
@ -310,7 +307,6 @@ public class OneToManyPersister extends AbstractCollectionPersister {
astCreationState
);
}
}
@Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {

View File

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
@ -3014,7 +3013,7 @@ public abstract class AbstractEntityPersister
TableGroup tableGroup,
SqlAstCreationState creationState) {
if ( needsDiscriminator() ) {
pruneForSubclasses( tableGroup, Collections.singletonMap( getEntityName(), EntityNameUse.TREAT ) );
predicateConsumer.accept( createDiscriminatorPredicate( alias, tableGroup, creationState ) );
}
}

View File

@ -3042,11 +3042,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
@Override
public boolean supportsEntityNameUsage() {
return true;
}
@Override
public void registerEntityNameUsage(
TableGroup tableGroup,

View File

@ -42,9 +42,4 @@ public interface SqlAstCreationState {
String hibernateEntityName) {
// No-op
}
@Internal
default boolean supportsEntityNameUsage() {
return false;
}
}

View File

@ -72,7 +72,7 @@ public class NamedTableReference extends AbstractTableReference {
@Override
public boolean containsAffectedTableName(String requestedName) {
return isEmpty( requestedName ) || getTableExpression().contains( requestedName );
return isEmpty( requestedName ) || getTableExpression().equals( requestedName );
}
@Override

View File

@ -44,8 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@DomainModel(annotatedClasses = {
OneToManyJoinFetchDiscriminatorTest.Person.class,
OneToManyJoinFetchDiscriminatorTest.BodyPart.class,
OneToManyJoinFetchDiscriminatorTest.Leg.class,
OneToManyJoinFetchDiscriminatorTest.Arm.class,
OneToManyJoinFetchDiscriminatorTest.Leg.class
})
@JiraKey("HHH-16157")
public class OneToManyJoinFetchDiscriminatorTest {
@ -137,23 +136,4 @@ public class OneToManyJoinFetchDiscriminatorTest {
return person;
}
}
@Entity(name = "Arm")
@DiscriminatorValue("ArmBodyPart")
public static class Arm extends BodyPart {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private Person person;
public Arm() {
}
public Arm(String name, Person person) {
this.name = name;
this.person = person;
}
public Person getPerson() {
return person;
}
}
}

View File

@ -1,149 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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.orm.test.mapping.inheritance;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Laurent Almeras
*/
@DomainModel( annotatedClasses = {
ManyToOneInheritanceSubTypeTest.SuperType.class,
ManyToOneInheritanceSubTypeTest.TypeA.class,
ManyToOneInheritanceSubTypeTest.TypeB.class,
ManyToOneInheritanceSubTypeTest.LinkedEntity.class
} )
@SessionFactory( useCollectingStatementInspector = true )
@Jira( "https://hibernate.atlassian.net/browse/HHH-16616" )
public class ManyToOneInheritanceSubTypeTest {
@BeforeAll
public void setUp(SessionFactoryScope scope) {
scope.inTransaction( session -> {
final SuperType superType = new SuperType( 1 );
final TypeB typeB = new TypeB( 2, "typeB" );
final TypeA typeA = new TypeA( 3, "typeA" );
final LinkedEntity entity = new LinkedEntity( 4 );
entity.addTypeA( typeA );
session.persist( superType );
session.persist( typeB );
session.persist( typeA );
session.persist( entity );
} );
}
@Test
public void testFind(SessionFactoryScope scope) {
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
inspector.clear();
scope.inTransaction( session -> {
final LinkedEntity entity = session.find( LinkedEntity.class, 4 );
assertThat( entity.getTypeAS() ).hasSize( 1 );
inspector.assertExecutedCount( 2 );
inspector.assertNumberOfOccurrenceInQueryNoSpace( 1, "disc_col", 1 );
} );
}
@Test
public void testJoinFetch(SessionFactoryScope scope) {
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
inspector.clear();
scope.inTransaction( session -> {
final LinkedEntity entity = session.createQuery(
"from LinkedEntity e left join fetch e.typeAS",
LinkedEntity.class
).getSingleResult();
assertThat( entity.getTypeAS() ).hasSize( 1 );
inspector.assertExecutedCount( 1 );
inspector.assertNumberOfOccurrenceInQueryNoSpace( 0, "disc_col", 1 );
} );
}
@Entity( name = "SuperType" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn( name = "disc_col" )
public static class SuperType {
@Id
private Integer id;
public SuperType() {
}
public SuperType(Integer id) {
this.id = id;
}
}
@Entity( name = "TypeA" )
public static class TypeA extends SuperType {
private String typeAName;
public TypeA() {
}
public TypeA(Integer id, String typeAName) {
super( id );
this.typeAName = typeAName;
}
}
@Entity( name = "TypeB" )
public static class TypeB extends SuperType {
private String typeBName;
public TypeB() {
}
public TypeB(Integer id, String typeBName) {
super( id );
this.typeBName = typeBName;
}
}
@Entity( name = "LinkedEntity" )
public static class LinkedEntity {
@Id
private Integer id;
@OneToMany
@JoinColumn( name = "linked_id" )
private List<TypeA> typeAS = new ArrayList<>();
public LinkedEntity() {
}
public LinkedEntity(Integer id) {
this.id = id;
}
public List<TypeA> getTypeAS() {
return typeAS;
}
public void addTypeA(TypeA typeA) {
this.typeAS.add( typeA );
}
}
}