Search in sources :

Example 56 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 {
    Session session = openSession();
    session.beginTransaction();
    try {
        Company company = new Company(1, "acme");
        Person person = new Person(1, "joe", company);
        session.persist(person);
        session.flush();
        company = person.employer;
        session.delete(company);
        session.delete(person);
        session.flush();
        session.persist(person);
        session.flush();
        session.getTransaction().commit();
    } catch (Exception e) {
        session.getTransaction().rollback();
        throw e;
    }
    session.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 57 with FailureExpected

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

the class MergeMultipleEntityCopiesAllowedTest method testNestedUnidirOneToManyBackrefWithNewElement.

@Test
@FailureExpected(jiraKey = "HHH-9239")
public void testNestedUnidirOneToManyBackrefWithNewElement() {
    Item item1 = new Item();
    item1.setName("item1 name");
    SubItem subItem1 = new SubItem();
    subItem1.setName("subItem1 name");
    item1.getSubItemsBackref().add(subItem1);
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.persist(item1);
    tx.commit();
    s.close();
    // get another representation of item1
    s = openSession();
    tx = s.beginTransaction();
    Item item1_1 = (Item) s.get(Item.class, item1.getId());
    Hibernate.initialize(item1_1.getSubItemsBackref());
    tx.commit();
    s.close();
    Category category = new Category();
    category.setName("category");
    item1.setCategory(category);
    SubItem subItem2 = new SubItem();
    subItem2.setName("subItem2 name");
    item1_1.getSubItemsBackref().add(subItem2);
    category.setExampleItem(item1_1);
    s = openSession();
    tx = s.beginTransaction();
    Item item1Merged = (Item) s.merge(item1);
    // The resulting collection should contain the added element
    assertEquals(2, item1Merged.getSubItemsBackref().size());
    assertEquals("subItem1 name", item1Merged.getSubItemsBackref().get(0).getName());
    assertEquals("subItem2 name", item1Merged.getSubItemsBackref().get(1).getName());
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    item1 = (Item) s.get(Item.class, item1.getId());
    assertEquals(2, item1.getSubItemsBackref().size());
    assertEquals("subItem1 name", item1.getSubItemsBackref().get(0).getName());
    assertEquals("subItem2 name", item1Merged.getSubItemsBackref().get(1).getName());
    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 58 with FailureExpected

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

the class MergeMultipleEntityCopiesAllowedOrphanDeleteTest method testNestedUnidirOneToManyBackrefWithRemovedElement.

@Test
@FailureExpected(jiraKey = "HHH-9239")
public void testNestedUnidirOneToManyBackrefWithRemovedElement() {
    Item item1 = new Item();
    item1.setName("item1 name");
    SubItem subItem1 = new SubItem();
    subItem1.setName("subItem1 name");
    item1.getSubItemsBackref().add(subItem1);
    SubItem subItem2 = new SubItem();
    subItem2.setName("subItem2 name");
    item1.getSubItemsBackref().add(subItem2);
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.persist(item1);
    tx.commit();
    s.close();
    // get another representation of item1
    s = openSession();
    tx = s.beginTransaction();
    Item item1_1 = (Item) s.get(Item.class, item1.getId());
    Hibernate.initialize(item1_1.getSubItemsBackref());
    tx.commit();
    s.close();
    // remove subItem1 from the nested Item
    item1_1.getSubItemsBackref().remove(subItem1);
    Category category = new Category();
    category.setName("category");
    item1.setCategory(category);
    category.setExampleItem(item1_1);
    s = openSession();
    tx = s.beginTransaction();
    Item item1Merged = (Item) s.merge(item1);
    // the element should have been removed
    assertEquals(1, item1Merged.getSubItemsBackref().size());
    assertTrue(item1Merged.getSubItemsBackref().contains(subItem2));
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    item1 = (Item) s.get(Item.class, item1.getId());
    assertEquals(1, item1.getSubItemsBackref().size());
    assertTrue(item1.getSubItemsBackref().contains(subItem2));
    // because cascade includes "delete-orphan" the removed SubItem should have been deleted.
    subItem1 = (SubItem) s.get(SubItem.class, subItem1.getId());
    assertNull(subItem1);
    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 59 with FailureExpected

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

the class NativeSQLQueriesTest method testCompositeIdJoins.

@Test
@SuppressWarnings({ "unchecked" })
@FailureExpected(jiraKey = "unknown")
public void testCompositeIdJoins() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Person person = new Person();
    person.setName("Noob");
    Product product = new Product();
    product.setProductId(new Product.ProductId());
    product.getProductId().setOrgid("x");
    product.getProductId().setProductnumber("1234");
    product.setName("Hibernate 3");
    Order order = new Order();
    order.setOrderId(new Order.OrderId());
    order.getOrderId().setOrdernumber("1");
    order.getOrderId().setOrgid("y");
    product.getOrders().add(order);
    order.setProduct(product);
    order.setPerson(person);
    s.save(product);
    s.save(order);
    s.save(person);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Product p = (Product) s.createQuery("from Product p join fetch p.orders").list().get(0);
    assertTrue(Hibernate.isInitialized(p.getOrders()));
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Object[] o = (Object[]) s.createSQLQuery("select\r\n" + "        product.orgid as {product.id.orgid}," + "        product.productnumber as {product.id.productnumber}," + "        {prod_orders}.orgid as orgid3_1_,\r\n" + "        {prod_orders}.ordernumber as ordernum2_3_1_,\r\n" + "        product.name as {product.name}," + "        {prod_orders.element.*}" + /*"        orders.PROD_NO as PROD4_3_1_,\r\n" +
				"        orders.person as person3_1_,\r\n" +
				"        orders.PROD_ORGID as PROD3_0__,\r\n" +
				"        orders.PROD_NO as PROD4_0__,\r\n" +
				"        orders.orgid as orgid0__,\r\n" +
				"        orders.ordernumber as ordernum2_0__ \r\n" +*/
    "    from\r\n" + "        Product product \r\n" + "    inner join\r\n" + "        TBL_ORDER {prod_orders} \r\n" + "            on product.orgid={prod_orders}.PROD_ORGID \r\n" + "            and product.productnumber={prod_orders}.PROD_NO").addEntity("product", Product.class).addJoin("prod_orders", "product.orders").list().get(0);
    p = (Product) o[0];
    assertTrue(Hibernate.isInitialized(p.getOrders()));
    assertNotNull(p.getOrders().iterator().next());
    t.commit();
    s.close();
}
Also used : Order(org.hibernate.test.sql.hand.Order) Transaction(org.hibernate.Transaction) Product(org.hibernate.test.sql.hand.Product) Person(org.hibernate.test.sql.hand.Person) 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