use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class ColumnWithExplicitReferenceToPrimaryTableTest method testColumnAnnotationWithExplicitReferenceToPrimaryTable.
@Test
@TestForIssue(jiraKey = "HHH-8539")
public void testColumnAnnotationWithExplicitReferenceToPrimaryTable() {
final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {
@Override
public List<String> getManagedClassNames() {
return Arrays.asList(AnEntity.class.getName());
}
};
final Map settings = new HashMap();
settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
emf.close();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class EntityGraphTest method inheritanceTest.
/**
* JPA 2.1 spec: "Add a node to the graph that corresponds to a managed type with inheritance. This allows for
* multiple subclass subgraphs to be defined for this node of the entity graph. Subclass subgraphs will
* automatically include the specified attributes of superclass subgraphs."
*/
@Test
@TestForIssue(jiraKey = "HHH-8640")
public void inheritanceTest() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Manager manager = new Manager();
em.persist(manager);
Employee employee = new Employee();
employee.friends.add(manager);
employee.managers.add(manager);
em.persist(employee);
Company company = new Company();
company.employees.add(employee);
company.employees.add(manager);
em.persist(company);
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
EntityGraph<Company> entityGraph = em.createEntityGraph(Company.class);
Subgraph<Employee> subgraph = entityGraph.addSubgraph("employees");
subgraph.addAttributeNodes("managers");
subgraph.addAttributeNodes("friends");
Subgraph<Manager> subSubgraph = subgraph.addSubgraph("managers", Manager.class);
subSubgraph.addAttributeNodes("managers");
subSubgraph.addAttributeNodes("friends");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("javax.persistence.loadgraph", entityGraph);
Company result = em.find(Company.class, company.id, properties);
assertTrue(Hibernate.isInitialized(result));
assertTrue(Hibernate.isInitialized(result.employees));
assertEquals(result.employees.size(), 2);
for (Employee resultEmployee : result.employees) {
assertTrue(Hibernate.isInitialized(resultEmployee.managers));
assertTrue(Hibernate.isInitialized(resultEmployee.friends));
}
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class EntityGraphTest method attributeNodeInheritanceTest.
@Test
@TestForIssue(jiraKey = "HHH-9080")
public void attributeNodeInheritanceTest() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Manager manager = new Manager();
em.persist(manager);
Employee employee = new Employee();
manager.friends.add(employee);
em.persist(employee);
Manager anotherManager = new Manager();
manager.managers.add(anotherManager);
em.persist(anotherManager);
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
EntityGraph<Manager> entityGraph = em.createEntityGraph(Manager.class);
entityGraph.addAttributeNodes("friends");
entityGraph.addAttributeNodes("managers");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("javax.persistence.loadgraph", entityGraph);
Manager result = em.find(Manager.class, manager.id, properties);
assertTrue(Hibernate.isInitialized(result));
assertTrue(Hibernate.isInitialized(result.friends));
assertEquals(result.friends.size(), 1);
assertTrue(Hibernate.isInitialized(result.managers));
assertEquals(result.managers.size(), 1);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class EntityGraphTest method loadMultipleAssociations.
@Test
@TestForIssue(jiraKey = "HHH-8857")
public void loadMultipleAssociations() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Bar bar = new Bar();
em.persist(bar);
Baz baz = new Baz();
em.persist(baz);
Foo foo = new Foo();
foo.bar = bar;
foo.baz = baz;
em.persist(foo);
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
EntityGraph<Foo> fooGraph = em.createEntityGraph(Foo.class);
fooGraph.addAttributeNodes("bar", "baz");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("javax.persistence.loadgraph", fooGraph);
Foo result = em.find(Foo.class, foo.id, properties);
assertTrue(Hibernate.isInitialized(result));
assertTrue(Hibernate.isInitialized(result.bar));
assertTrue(Hibernate.isInitialized(result.baz));
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class InheritedEntityGraphTest method singleAttributeSubgraphInheritanceTest.
@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();
}
Aggregations