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();
}
}
Aggregations