Search in sources :

Example 1 with Address

use of org.jpwh.model.complexschemas.secondarytable.Address in project microservices by pwillhan.

the class SecondaryTable method storeAndLoadUsers.

@Test
public void storeAndLoadUsers() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        User user = new User();
        user.setUsername("johndoe");
        Address homeAddress = new Address("Some Street 123", "12345", "Some City");
        user.setHomeAddress(homeAddress);
        em.persist(user);
        tx.commit();
        em.close();
        tx.begin();
        em = JPA.createEntityManager();
        User u = em.find(User.class, user.getId());
        assertEquals(u.getUsername(), "johndoe");
        assertEquals(u.getHomeAddress().getStreet(), "Some Street 123");
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.complexschemas.secondarytable.User) Address(org.jpwh.model.complexschemas.secondarytable.Address) 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 Address (org.jpwh.model.complexschemas.secondarytable.Address)1 User (org.jpwh.model.complexschemas.secondarytable.User)1 Test (org.testng.annotations.Test)1