HHH-15972 entitygraph load error when Inheritance JOINED is used in 6.1.6

This commit is contained in:
Réda Housni Alaoui 2023-01-26 15:22:36 +01:00 committed by Steve Ebersole
parent 20f4598cb2
commit e1512c0ea6
2 changed files with 65 additions and 4 deletions

View File

@ -21,7 +21,6 @@ import org.hibernate.graph.SubGraph;
import org.hibernate.graph.spi.AttributeNodeImplementor;
import org.hibernate.graph.spi.GraphImplementor;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
@ -139,7 +138,7 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
@Override
@SuppressWarnings("unchecked")
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
final PersistentAttribute<? super J, ?> attribute = managedType.findAttribute( attributeName );
final PersistentAttribute<? super J, ?> attribute = managedType.findAttributeInSuperTypes( attributeName );
if ( attribute == null ) {
return null;
}

View File

@ -16,12 +16,16 @@ import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Subgraph;
@ -50,8 +54,10 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Foo.class, Bar.class, Baz.class, Author.class, Book.class, Prize.class,
Company.class, Employee.class, Manager.class, Location.class };
return new Class[] {
Foo.class, Bar.class, Baz.class, Author.class, Book.class, Prize.class,
Company.class, Employee.class, Manager.class, Location.class, Animal.class, Dog.class, Cat.class
};
}
@Test
@ -424,6 +430,30 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase {
em.close();
}
@Test
@TestForIssue(jiraKey = "HHH-15972")
public void joinedInheritanceWithAttributeConflictTest() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Dog dog = new Dog();
em.persist( dog );
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
Map<String, Object> properties = new HashMap<>();
properties.put( "jakarta.persistence.loadgraph", em.createEntityGraph( Animal.class ) );
Animal animal = em.find( Animal.class, dog.id, properties );
assertTrue( animal instanceof Dog );
assertEquals( dog.id, animal.id );
em.getTransaction().commit();
em.close();
}
@Entity
@Table(name = "foo")
public static class Foo {
@ -526,4 +556,36 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase {
this.name = name;
}
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public static abstract class Animal {
@Id
@GeneratedValue
public Integer id;
public String dtype;
public String name;
}
@Entity
@DiscriminatorValue("DOG")
public static class Dog extends Animal {
public Integer numberOfLegs;
public Dog() {
dtype = "DOG";
}
}
@Entity
@DiscriminatorValue("CAT")
public static class Cat extends Animal {
public Integer numberOfLegs;
public Cat() {
dtype = "CAT";
}
}
}