Search in sources :

Example 16 with FailureExpected

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

the class BulkManipulationTest method testBulkDeleteOfMultiTableEntityWithElementCollection.

@Test
@FailureExpected(jiraKey = "HHH-9282", message = "failed because HHH-9222 was reverted by HHH-9282")
public void testBulkDeleteOfMultiTableEntityWithElementCollection() {
    // set up test data
    {
        Session s = openSession();
        s.beginTransaction();
        Human human = new Human();
        human.setNickNames(new TreeSet());
        human.getNickNames().add("Johnny");
        s.save(human);
        s.getTransaction().commit();
        s.close();
    }
    // assertion that nickname collection table got populated
    {
        Session s = openSession();
        s.beginTransaction();
        s.doWork(new Work() {

            @Override
            public void execute(Connection connection) throws SQLException {
                final Statement statement = connection.createStatement();
                final ResultSet resultSet = statement.executeQuery("select count(*) from human_nick_names");
                assertTrue(resultSet.next());
                final int count = resultSet.getInt(1);
                assertEquals(1, count);
            }
        });
        s.getTransaction().commit();
        s.close();
    }
    // do delete
    {
        Session s = openSession();
        s.beginTransaction();
        s.createQuery("delete Human").executeUpdate();
        s.getTransaction().commit();
        s.close();
    }
    // assertion that nickname collection table got cleaned up
    //		if they didn't, the delete should have caused a constraint error, but just to be sure...
    {
        Session s = openSession();
        s.beginTransaction();
        s.doWork(new Work() {

            @Override
            public void execute(Connection connection) throws SQLException {
                final Statement statement = connection.createStatement();
                final ResultSet resultSet = statement.executeQuery("select count(*) from human_nick_names");
                assertTrue(resultSet.next());
                final int count = resultSet.getInt(1);
                assertEquals(0, count);
            }
        });
        s.getTransaction().commit();
        s.close();
    }
}
Also used : TreeSet(java.util.TreeSet) Statement(java.sql.Statement) Work(org.hibernate.jdbc.Work) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 17 with FailureExpected

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

the class ASTParserLoadingTest method testParameterTypeMismatch.

@Test
@FailureExpected(jiraKey = "unknown")
public void testParameterTypeMismatch() {
    Session s = openSession();
    s.beginTransaction();
    Query query = s.createQuery("from Animal a where a.description = :nonstring").setParameter("nonstring", Integer.valueOf(1));
    try {
        query.list();
        fail("query execution should have failed");
    } catch (IllegalArgumentException e) {
        assertTyping(TypeMismatchException.class, e.getCause());
    } catch (TypeMismatchException tme) {
    // expected behavior
    }
    s.getTransaction().commit();
    s.close();
}
Also used : Query(org.hibernate.Query) TypeMismatchException(org.hibernate.TypeMismatchException) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 18 with FailureExpected

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

the class TreatKeywordTest method testRestrictionsOnJoinedSubclasses.

@Test
@TestForIssue(jiraKey = "HHH-9862")
@FailureExpected(jiraKey = "HHH-9862")
public void testRestrictionsOnJoinedSubclasses() {
    Session s = openSession();
    s.beginTransaction();
    JoinedEntity root = new JoinedEntity(1, "root");
    s.save(root);
    JoinedEntitySubclass child1 = new JoinedEntitySubclass(2, "child1", root);
    s.save(child1);
    JoinedEntitySubclass2 child2 = new JoinedEntitySubclass2(3, "child2", root);
    s.save(child2);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    List result = s.createQuery("select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1'").list();
    assertEquals(1, result.size());
    assertTrue(JoinedEntitySubclass.class.isInstance(result.get(0)));
    result = s.createQuery("select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child1'").list();
    assertEquals(0, result.size());
    result = s.createQuery("select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child2'").list();
    assertEquals(1, result.size());
    assertTrue(JoinedEntitySubclass2.class.isInstance(result.get(0)));
    result = s.createQuery("select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1' or treat (e as JoinedEntitySubclass2 ).name = 'child2'").list();
    assertEquals(2, result.size());
    s.close();
    s = openSession();
    s.beginTransaction();
    s.delete(child1);
    s.delete(child2);
    s.delete(root);
    s.getTransaction().commit();
    s.close();
}
Also used : List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 19 with FailureExpected

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

the class MergeMultipleEntityCopiesAllowedOrphanDeleteTest method testNestedUnidirOneToManyNoBackrefWithRemovedElement.

@Test
@FailureExpected(jiraKey = "HHH-9239")
public void testNestedUnidirOneToManyNoBackrefWithRemovedElement() {
    Category category1 = new Category();
    category1.setName("category1 name");
    SubCategory subCategory1 = new SubCategory();
    subCategory1.setName("subCategory1 name");
    category1.getSubCategories().add(subCategory1);
    SubCategory subCategory2 = new SubCategory();
    subCategory2.setName("subCategory2 name");
    category1.getSubCategories().add(subCategory2);
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.persist(category1);
    tx.commit();
    s.close();
    // get another representation of category1
    s = openSession();
    tx = s.beginTransaction();
    Category category1_1 = (Category) s.get(Category.class, category1.getId());
    Hibernate.initialize(category1_1.getSubCategories());
    tx.commit();
    s.close();
    category1_1.getSubCategories().remove(subCategory2);
    Item item = new Item();
    item.setName("item");
    category1.setExampleItem(item);
    item.setCategory(category1_1);
    s = openSession();
    tx = s.beginTransaction();
    Category category1Merged = (Category) s.merge(category1);
    assertEquals(1, category1Merged.getSubCategories().size());
    assertTrue(category1Merged.getSubCategories().contains(subCategory2));
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    category1 = (Category) s.get(Category.class, category1.getId());
    assertEquals(1, category1.getSubCategories().size());
    assertTrue(category1.getSubCategories().contains(subCategory2));
    subCategory1 = (SubCategory) s.get(SubCategory.class, subCategory1.getId());
    assertNull(subCategory1);
    tx.commit();
    s.close();
    cleanup();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 20 with FailureExpected

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

the class MergeMultipleEntityCopiesAllowedOrphanDeleteTest method testNestedUnidirOneToManyNoBackrefWithNewElement.

@Test
@FailureExpected(jiraKey = "HHH-9239")
public void testNestedUnidirOneToManyNoBackrefWithNewElement() {
    Category category1 = new Category();
    category1.setName("category1 name");
    SubCategory subCategory1 = new SubCategory();
    subCategory1.setName("subCategory1 name");
    category1.getSubCategories().add(subCategory1);
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.persist(category1);
    tx.commit();
    s.close();
    // get another representation of category1
    s = openSession();
    tx = s.beginTransaction();
    Category category1_1 = (Category) s.get(Category.class, category1.getId());
    Hibernate.initialize(category1_1.getSubCategories());
    tx.commit();
    s.close();
    SubCategory subCategory2 = new SubCategory();
    subCategory2.setName("subCategory2 name");
    category1_1.getSubCategories().add(subCategory2);
    Item item = new Item();
    item.setName("item");
    category1.setExampleItem(item);
    item.setCategory(category1_1);
    s = openSession();
    tx = s.beginTransaction();
    Category category1Merged = (Category) s.merge(category1);
    // new element should be there
    assertEquals(2, category1Merged.getSubCategories().size());
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    category1 = (Category) s.get(Category.class, category1.getId());
    assertEquals(2, category1.getSubCategories().size());
    tx.commit();
    s.close();
    cleanup();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

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