Search in sources :

Example 36 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class MappedSuperclassType2Test method testMappedSuperclassAccessNoEntity.

@Test
@TestForIssue(jiraKey = "HHH-8534")
@FailureExpected(jiraKey = "HHH-8534")
public void testMappedSuperclassAccessNoEntity() {
    // stupid? yes.  tck does it? yes.
    final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {

        @Override
        public List<String> getManagedClassNames() {
            // pass in a MappedSuperclass that is not used in any entity hierarchy
            return Arrays.asList(SomeMappedSuperclass.class.getName());
        }
    };
    final Map settings = new HashMap();
    settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
    EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
    try {
        ManagedType<SomeMappedSuperclass> type = emf.getMetamodel().managedType(SomeMappedSuperclass.class);
        // the issue was in regards to throwing an exception, but also check for nullness
        assertNotNull(type);
    } finally {
        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) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 37 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class RemoveOrderingTest method testManyToOne.

@Test
@TestForIssue(jiraKey = "HHH-8550")
@FailureExpected(jiraKey = "HHH-8550")
public void testManyToOne() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    try {
        Company company = new Company(1, "acme");
        Person person = new Person(1, "joe", company);
        em.persist(person);
        em.flush();
        em.remove(company);
        em.remove(person);
        em.flush();
        em.persist(person);
        em.flush();
        em.getTransaction().commit();
    } catch (Exception e) {
        em.getTransaction().rollback();
        throw e;
    }
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 38 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class DeleteOneToManyOrphansTest method testOrphanedWhileManaged.

@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testOrphanedWhileManaged() {
    createData();
    EntityManager entityManager = getOrCreateEntityManager();
    entityManager.getTransaction().begin();
    List results = entityManager.createQuery("from Feature").getResultList();
    assertEquals(1, results.size());
    results = entityManager.createQuery("from Product").getResultList();
    assertEquals(1, results.size());
    Product product = (Product) results.get(0);
    assertEquals(1, product.getFeatures().size());
    product.getFeatures().clear();
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManager = getOrCreateEntityManager();
    entityManager.getTransaction().begin();
    product = entityManager.find(Product.class, product.getId());
    assertEquals(0, product.getFeatures().size());
    results = entityManager.createQuery("from Feature").getResultList();
    assertEquals(0, results.size());
    results = entityManager.createQuery("from Product").getResultList();
    assertEquals(1, results.size());
    entityManager.getTransaction().commit();
    entityManager.close();
    cleanupData();
}
Also used : EntityManager(javax.persistence.EntityManager) List(java.util.List) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 39 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class DeleteOneToManyOrphansTest method testReplacedWhileManaged.

@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testReplacedWhileManaged() {
    createData();
    EntityManager entityManager = getOrCreateEntityManager();
    entityManager.getTransaction().begin();
    List results = entityManager.createQuery("from Feature").getResultList();
    assertEquals(1, results.size());
    results = entityManager.createQuery("from Product").getResultList();
    assertEquals(1, results.size());
    Product product = (Product) results.get(0);
    assertEquals(1, product.getFeatures().size());
    // Replace with a new Feature instance
    product.getFeatures().remove(0);
    Feature featureNew = new Feature();
    featureNew.setName("Feature 2");
    featureNew.setProduct(product);
    product.getFeatures().add(featureNew);
    entityManager.persist(featureNew);
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManager = getOrCreateEntityManager();
    entityManager.getTransaction().begin();
    results = entityManager.createQuery("from Feature").getResultList();
    assertEquals(1, results.size());
    Feature featureQueried = (Feature) results.get(0);
    assertEquals(featureNew.getId(), featureQueried.getId());
    results = entityManager.createQuery("from Product").getResultList();
    assertEquals(1, results.size());
    Product productQueried = (Product) results.get(0);
    assertEquals(1, productQueried.getFeatures().size());
    assertEquals(featureQueried, productQueried.getFeatures().get(0));
    entityManager.getTransaction().commit();
    entityManager.close();
    cleanupData();
}
Also used : EntityManager(javax.persistence.EntityManager) List(java.util.List) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 40 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class JoinColumnOrFormulaTest method testUseOfJoinColumnOrFormula.

@Test
@TestForIssue(jiraKey = "HHH-9897")
@FailureExpected(jiraKey = "HHH-9897")
public void testUseOfJoinColumnOrFormula() {
    Metadata metadata = new MetadataSources().addAnnotatedClass(A.class).addAnnotatedClass(D.class).buildMetadata();
    // Binding to the mapping model works afterQuery the simple change for HHH-9897
    // But building the SessionFactory fails in the collection persister trying to
    // use the formula (it expects Columns too)
    metadata.buildSessionFactory().close();
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

FailureExpected (org.hibernate.testing.FailureExpected)59 Test (org.junit.Test)58 Session (org.hibernate.Session)39 Transaction (org.hibernate.Transaction)23 TestForIssue (org.hibernate.testing.TestForIssue)14 EntityManager (javax.persistence.EntityManager)12 List (java.util.List)7 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 MetadataSources (org.hibernate.boot.MetadataSources)3 RequiresDialect (org.hibernate.testing.RequiresDialect)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Callable (java.util.concurrent.Callable)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Query (javax.persistence.Query)2