Search in sources :

Example 1 with StolenCreditCard

use of org.jpwh.model.bulkbatch.StolenCreditCard in project microservices by pwillhan.

the class BulkStatementsJPQL method bulkInsert.

@Test
public void bulkInsert() throws Exception {
    BulkBatchTestData testData = storeTestData();
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        int createdRecords = em.createQuery("insert into" + " StolenCreditCard(id, owner, cardNumber, expMonth, expYear, userId, username)" + " select c.id, c.owner, c.cardNumber, c.expMonth, c.expYear, u.id, u.username" + " from CreditCard c join c.user u where c.owner like 'J%'").executeUpdate();
        assertEquals(createdRecords, 1);
        List<StolenCreditCard> stolenCreditCards = em.createQuery("select sc from StolenCreditCard sc").getResultList();
        assertEquals(stolenCreditCards.size(), 1);
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) StolenCreditCard(org.jpwh.model.bulkbatch.StolenCreditCard) 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 StolenCreditCard (org.jpwh.model.bulkbatch.StolenCreditCard)1 Test (org.testng.annotations.Test)1