mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-22 02:58:05 +00:00
HHH-10261 - Test showing Exception if subgraph is created on an inherited attribute
This commit is contained in:
parent
3642bb63cd
commit
13fa120240
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.jpa.test.graphs.inherited;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Oliver Breidenbach
|
||||
*/
|
||||
@Entity
|
||||
public class Bar {
|
||||
@Id @GeneratedValue
|
||||
public long id;
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.jpa.test.graphs.inherited;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
|
||||
/**
|
||||
* @author Oliver Breidenbach
|
||||
*/
|
||||
@Entity
|
||||
public class Foo extends MappedSupperclass {
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.jpa.test.graphs.inherited;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
|
||||
/**
|
||||
* @author Oliver Breidenbach
|
||||
*/
|
||||
@Entity
|
||||
public class Foo2 {
|
||||
@Id @GeneratedValue
|
||||
public long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
public Foo foo;
|
||||
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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.jpa.test.graphs.inherited;
|
||||
|
||||
import javax.persistence.EntityGraph;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Subgraph;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Oliver Breidenbach
|
||||
*/
|
||||
public class InheritedEntityGraphTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Foo2.class, Foo.class, Bar.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10261")
|
||||
public void singleAttributeNodeInheritanceTest() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Bar bar = new Bar();
|
||||
em.persist(bar);
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.bar = bar;
|
||||
em.persist( foo );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
|
||||
em.getTransaction().begin();
|
||||
|
||||
EntityGraph<Foo> entityGraph = em.createEntityGraph( Foo.class );
|
||||
entityGraph.addSubgraph( "bar" );
|
||||
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put( "javax.persistence.loadgraph", entityGraph );
|
||||
|
||||
Foo result = em.find( Foo.class, foo.id, properties );
|
||||
|
||||
assertTrue( Hibernate.isInitialized( result ) );
|
||||
assertTrue( Hibernate.isInitialized( result.bar ) );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10261")
|
||||
public void collectionAttributeNodeInheritanceTest() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Bar bar = new Bar();
|
||||
em.persist(bar);
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.bar = bar;
|
||||
em.persist( foo );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
|
||||
em.getTransaction().begin();
|
||||
|
||||
EntityGraph<Foo> entityGraph = em.createEntityGraph( Foo.class );
|
||||
entityGraph.addSubgraph( "bars" );
|
||||
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put( "javax.persistence.loadgraph", entityGraph );
|
||||
|
||||
Foo result = em.find( Foo.class, foo.id, properties );
|
||||
|
||||
assertTrue( Hibernate.isInitialized( result ) );
|
||||
assertTrue( Hibernate.isInitialized( result.bars ) );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10261")
|
||||
public void singleAttributeSubgraphInheritanceTest() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Bar bar = new Bar();
|
||||
em.persist(bar);
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.bar = bar;
|
||||
em.persist( foo );
|
||||
|
||||
Foo2 foo2 = new Foo2();
|
||||
foo2.foo = foo;
|
||||
em.persist( foo2 );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
|
||||
em.getTransaction().begin();
|
||||
|
||||
EntityGraph<Foo2> entityGraph = em.createEntityGraph( Foo2.class );
|
||||
Subgraph<Foo> subgraphFoo = entityGraph.addSubgraph( "foo" );
|
||||
subgraphFoo.addSubgraph( "bar" );
|
||||
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put( "javax.persistence.loadgraph", entityGraph );
|
||||
|
||||
Foo2 result = em.find( Foo2.class, foo2.id, properties );
|
||||
|
||||
assertTrue( Hibernate.isInitialized( result ) );
|
||||
assertTrue( Hibernate.isInitialized( result.foo ) );
|
||||
assertTrue( Hibernate.isInitialized( result.foo.bar ) );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10261")
|
||||
public void collectionAttributeSubgraphInheritanceTest() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
Bar bar = new Bar();
|
||||
em.persist(bar);
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.bar = bar;
|
||||
em.persist( foo );
|
||||
|
||||
Foo2 foo2 = new Foo2();
|
||||
foo2.foo = foo;
|
||||
em.persist( foo2 );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
|
||||
em.getTransaction().begin();
|
||||
|
||||
EntityGraph<Foo2> entityGraph = em.createEntityGraph( Foo2.class );
|
||||
Subgraph<Foo> subgraphFoo = entityGraph.addSubgraph( "foo" );
|
||||
subgraphFoo.addSubgraph( "bars" );
|
||||
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put( "javax.persistence.loadgraph", entityGraph );
|
||||
|
||||
Foo2 result = em.find( Foo2.class, foo2.id, properties );
|
||||
|
||||
assertTrue( Hibernate.isInitialized( result ) );
|
||||
assertTrue( Hibernate.isInitialized( result.foo ) );
|
||||
assertTrue( Hibernate.isInitialized( result.foo.bars ) );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.jpa.test.graphs.inherited;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* @author Oliver Breidenbach
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class MappedSupperclass {
|
||||
@Id @GeneratedValue
|
||||
public long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
public Bar bar;
|
||||
|
||||
@OneToMany
|
||||
public Set<Bar> bars = new HashSet<Bar>();
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user