HHH-15972 entitygraph load error when Inheritance JOINED is used in 6.1.6
This commit is contained in:
parent
20f4598cb2
commit
e1512c0ea6
|
@ -21,7 +21,6 @@ import org.hibernate.graph.SubGraph;
|
||||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||||
import org.hibernate.graph.spi.GraphImplementor;
|
import org.hibernate.graph.spi.GraphImplementor;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
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.EntityDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
|
@ -139,7 +138,7 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
|
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 ) {
|
if ( attribute == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,16 @@ import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.persistence.DiscriminatorValue;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityGraph;
|
import jakarta.persistence.EntityGraph;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Inheritance;
|
||||||
|
import jakarta.persistence.InheritanceType;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.Subgraph;
|
import jakarta.persistence.Subgraph;
|
||||||
|
@ -50,8 +54,10 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[] { Foo.class, Bar.class, Baz.class, Author.class, Book.class, Prize.class,
|
return new Class[] {
|
||||||
Company.class, Employee.class, Manager.class, Location.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
|
@Test
|
||||||
|
@ -424,6 +430,30 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
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
|
@Entity
|
||||||
@Table(name = "foo")
|
@Table(name = "foo")
|
||||||
public static class Foo {
|
public static class Foo {
|
||||||
|
@ -526,4 +556,36 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
this.name = name;
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue