use of org.jpwh.model.advanced.City in project microservices by pwillhan.
the class NestedComponents method storeAndLoadUsers.
@Test
public void storeAndLoadUsers() throws Exception {
UserTransaction tx = TM.getUserTransaction();
try {
tx.begin();
EntityManager em = JPA.createEntityManager();
City city = new City();
city.setZipcode("12345");
city.setName("Some City");
city.setCountry(Locale.GERMANY.getCountry());
Address address = new Address();
address.setStreet("Some Street 123");
address.setCity(city);
User userOne = new User();
userOne.setAddress(address);
em.persist(userOne);
tx.commit();
em.close();
tx.begin();
em = JPA.createEntityManager();
User u = em.find(User.class, userOne.getId());
assertEquals(u.getAddress().getStreet(), "Some Street 123");
assertEquals(u.getAddress().getCity().getZipcode(), "12345");
assertEquals(u.getAddress().getCity().getCountry(), Locale.GERMANY.getCountry());
tx.commit();
em.close();
} finally {
TM.rollback();
}
}
Aggregations