use of org.jpwh.model.complexschemas.secondarytable.User 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();
}
}
Aggregations