Search in sources :

Example 51 with TestForIssue

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();
}
Also used : HashMap(java.util.HashMap) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUnitDescriptorAdapter(org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 52 with TestForIssue

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();
}
Also used : EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 53 with TestForIssue

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();
}
Also used : EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 54 with TestForIssue

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();
}
Also used : EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 55 with TestForIssue

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();
}
Also used : EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

TestForIssue (org.hibernate.testing.TestForIssue)649 Test (org.junit.Test)647 Session (org.hibernate.Session)357 EntityManager (javax.persistence.EntityManager)97 List (java.util.List)91 Transaction (org.hibernate.Transaction)88 MetadataSources (org.hibernate.boot.MetadataSources)47 ArrayList (java.util.ArrayList)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)38 Query (org.hibernate.Query)28 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)25 Metadata (org.hibernate.boot.Metadata)24 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)24 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Map (java.util.Map)22 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)19 HashMap (java.util.HashMap)18 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)18 PersistentClass (org.hibernate.mapping.PersistentClass)18 HibernateException (org.hibernate.HibernateException)16