Search in sources :

Example 1 with Bid

use of org.jpwh.model.complexschemas.custom.Bid in project microservices by pwillhan.

the class CustomSchema method storeLoadCheckSubselectValid.

@Test(expectedExceptions = org.hibernate.exception.ConstraintViolationException.class)
public void storeLoadCheckSubselectValid() throws Throwable {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        Item item = new Item("Some Item", CalendarUtil.TODAY.getTime(), CalendarUtil.TOMORROW.getTime());
        Bid bid = new Bid(new BigDecimal(1), item);
        // Out of date range of auction
        bid.setCreatedOn(CalendarUtil.AFTER_TOMORROW.getTime());
        item.getBids().add(bid);
        em.persist(item);
        em.persist(bid);
        try {
            em.flush();
        } catch (Exception ex) {
            throw unwrapCauseOfType(ex, org.hibernate.exception.ConstraintViolationException.class);
        }
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.complexschemas.custom.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.complexschemas.custom.Bid) BigDecimal(java.math.BigDecimal) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)1 EntityManager (javax.persistence.EntityManager)1 UserTransaction (javax.transaction.UserTransaction)1 JPATest (org.jpwh.env.JPATest)1 Bid (org.jpwh.model.complexschemas.custom.Bid)1 Item (org.jpwh.model.complexschemas.custom.Item)1 Test (org.testng.annotations.Test)1