Search in sources :

Example 1 with Item

use of org.jpwh.model.collections.setofstrings.Item in project microservices by pwillhan.

the class SetOfStrings method storeLoadCollection.

@Test
public void storeLoadCollection() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        Item someItem = new Item();
        someItem.getImages().add("foo.jpg");
        someItem.getImages().add("bar.jpg");
        someItem.getImages().add("baz.jpg");
        // Duplicate, filtered at Java level by HashSet!
        someItem.getImages().add("baz.jpg");
        em.persist(someItem);
        tx.commit();
        em.close();
        Long ITEM_ID = someItem.getId();
        tx.begin();
        em = JPA.createEntityManager();
        Item item = em.find(Item.class, ITEM_ID);
        assertEquals(item.getImages().size(), 3);
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.collections.setofstrings.Item) EntityManager(javax.persistence.EntityManager) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)1 UserTransaction (javax.transaction.UserTransaction)1 JPATest (org.jpwh.env.JPATest)1 Item (org.jpwh.model.collections.setofstrings.Item)1 Test (org.testng.annotations.Test)1