Search in sources :

Example 41 with FailureExpected

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

the class ExtraLazyTest method testWhereClauseOnUnidirectionalCollection.

@Test
@FailureExpected(jiraKey = "HHH-3319")
public void testWhereClauseOnUnidirectionalCollection() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Championship championship = new Championship(1);
    s.persist(championship);
    Student gavin = new Student("gavin", 4);
    Student turin = new Student("turin", 3);
    Student mike = new Student("mike", 5);
    Student fred = new Student("fred", 2);
    championship.getStudents().add(gavin);
    championship.getStudents().add(turin);
    championship.getStudents().add(mike);
    championship.getStudents().add(fred);
    s.persist(gavin);
    s.persist(turin);
    s.persist(mike);
    s.persist(fred);
    t.commit();
    s.close();
    s = openSession();
    Championship championship2 = s.get(Championship.class, 1);
    assertEquals(2, championship2.getStudents().size());
    assertTrue(championship2.getStudents().contains(gavin));
    assertTrue(championship2.getStudents().contains(mike));
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 42 with FailureExpected

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

the class BrokenCollectionEventTest method testSaveParentNullChildren.

// The following fails for the same reason as testUpdateDetachedParentNoChildrenToNullFailureExpected
// When that issue is fixed, this one should also be fixed and moved into AbstractCollectionEventTest.
/*
	public void testUpdateDetachedParentOneChildToNullFailureExpected() {
		CollectionListeners listeners = new CollectionListeners( sessionFactory() );
		ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
		Child oldChild = ( Child ) parent.getChildren().iterator().next();
		assertEquals( 1, parent.getChildren().size() );
		listeners.clear();
		Session s = openSession();
		Transaction tx = s.beginTransaction();
		Collection oldCollection = parent.getChildren();
		parent.newChildren( null );
		s.update( parent );
		tx.commit();
		s.close();
		int index = 0;
		checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
		checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
		if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
		}
		// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
		checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
		checkNumberOfResults( listeners, index );
	}
	*/
@Test
@FailureExpected(jiraKey = "unknown")
public void testSaveParentNullChildren() {
    CollectionListeners listeners = new CollectionListeners(sessionFactory());
    ParentWithCollection parent = createParentWithNullChildren("parent");
    assertNull(parent.getChildren());
    int index = 0;
    // pre- and post- collection recreate events should be created when creating an entity with a "null" collection
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    checkNumberOfResults(listeners, index);
    listeners.clear();
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    parent = (ParentWithCollection) s.get(parent.getClass(), parent.getId());
    tx.commit();
    s.close();
    assertNotNull(parent.getChildren());
    checkNumberOfResults(listeners, 0);
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 43 with FailureExpected

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

the class MergeListPreAndPostPersistWithIdentityTest method testAllPropertiesCopied.

@Test
@TestForIssue(jiraKey = "HHH-9979")
@FailureExpected(jiraKey = "HHH-9979")
public void testAllPropertiesCopied() {
    final Order order = new Order();
    order.id = 1L;
    order.name = "order";
    // Item.id is an identity so don't initialize it.
    Item item = new Item();
    item.name = "item";
    order.items.add(item);
    addEntityListeners(order);
    Session s = openSession();
    s.getTransaction().begin();
    s.merge(order);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.getTransaction().begin();
    s.delete(order);
    s.getTransaction().commit();
    s.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 44 with FailureExpected

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

the class SQLLoaderTest method testReturnPropertyComponentRename.

@Test
@FailureExpected(jiraKey = "unknown")
public void testReturnPropertyComponentRename() throws HibernateException, SQLException {
    // failure expected because this was a regression introduced previously which needs to get tracked down.
    Componentizable componentizable = setupComponentData();
    Session session = openSession();
    session.beginTransaction();
    Query namedQuery = session.getNamedQuery("queryComponentWithOtherColumn");
    List list = namedQuery.list();
    assertEquals(1, list.size());
    assertEquals("flakky comp", ((Componentizable) list.get(0)).getComponent().getName());
    session.clear();
    session.delete(componentizable);
    session.getTransaction().commit();
    session.close();
}
Also used : SQLQuery(org.hibernate.SQLQuery) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 45 with FailureExpected

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

the class ParentChildTest method testProxyReuse.

@Test
@FailureExpected(jiraKey = "unknown")
public void testProxyReuse() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    FooProxy foo = new Foo();
    FooProxy foo2 = new Foo();
    Serializable id = s.save(foo);
    Serializable id2 = s.save(foo2);
    foo2.setInt(1234567);
    foo.setInt(1234);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    foo = (FooProxy) s.load(Foo.class, id);
    foo2 = (FooProxy) s.load(Foo.class, id2);
    assertFalse(Hibernate.isInitialized(foo));
    Hibernate.initialize(foo2);
    Hibernate.initialize(foo);
    assertTrue(foo.getComponent().getImportantDates().length == 4);
    assertTrue(foo2.getComponent().getImportantDates().length == 4);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    foo.setKey("xyzid");
    foo.setFloat(new Float(1.2f));
    //intentionally id, not id2!
    foo2.setKey((String) id);
    foo2.setFloat(new Float(1.3f));
    foo2.getDependent().setKey(null);
    foo2.getComponent().getSubcomponent().getFee().setKey(null);
    assertFalse(foo2.getKey().equals(id));
    s.save(foo);
    s.update(foo2);
    assertEquals(foo2.getKey(), id);
    assertTrue(foo2.getInt() == 1234567);
    assertEquals(foo.getKey(), "xyzid");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    foo = (FooProxy) s.load(Foo.class, id);
    assertTrue(foo.getInt() == 1234567);
    assertTrue(foo.getComponent().getImportantDates().length == 4);
    String feekey = foo.getDependent().getKey();
    String fookey = foo.getKey();
    s.delete(foo);
    s.delete(s.get(Foo.class, id2));
    s.delete(s.get(Foo.class, "xyzid"));
    // here is the issue (HHH-4092).  After the deletes above there are 2 Fees and a Glarch unexpectedly hanging around
    assertEquals(2, doDelete(s, "from java.lang.Object"));
    t.commit();
    s.close();
    //to account for new id rollback shit
    foo.setKey(fookey);
    foo.getDependent().setKey(feekey);
    foo.getComponent().setGlarch(null);
    foo.getComponent().setSubcomponent(null);
    s = openSession();
    t = s.beginTransaction();
    //foo.getComponent().setGlarch(null); //no id property!
    s.replicate(foo, ReplicationMode.OVERWRITE);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Foo refoo = (Foo) s.get(Foo.class, id);
    assertEquals(feekey, refoo.getDependent().getKey());
    s.delete(refoo);
    t.commit();
    s.close();
}
Also used : Serializable(java.io.Serializable) 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