use of org.jpwh.model.fetching.proxy.Category in project microservices by pwillhan.
the class LazyProxyCollections method storeTestData.
public FetchTestData storeTestData() throws Exception {
UserTransaction tx = TM.getUserTransaction();
tx.begin();
EntityManager em = JPA.createEntityManager();
Long[] categoryIds = new Long[3];
Long[] itemIds = new Long[3];
Long[] userIds = new Long[3];
User johndoe = new User("johndoe");
em.persist(johndoe);
userIds[0] = johndoe.getId();
User janeroe = new User("janeroe");
em.persist(janeroe);
userIds[1] = janeroe.getId();
User robertdoe = new User("robertdoe");
em.persist(robertdoe);
userIds[2] = robertdoe.getId();
Category category = new Category("Category One");
em.persist(category);
categoryIds[0] = category.getId();
Item item = new Item("Item One", CalendarUtil.TOMORROW.getTime(), johndoe);
em.persist(item);
itemIds[0] = item.getId();
category.getItems().add(item);
item.getCategories().add(category);
for (int i = 1; i <= 3; i++) {
Bid bid = new Bid(item, robertdoe, new BigDecimal(9 + i));
item.getBids().add(bid);
em.persist(bid);
}
category = new Category("Category Two");
em.persist(category);
categoryIds[1] = category.getId();
item = new Item("Item Two", CalendarUtil.TOMORROW.getTime(), johndoe);
em.persist(item);
itemIds[1] = item.getId();
category.getItems().add(item);
item.getCategories().add(category);
for (int i = 1; i <= 1; i++) {
Bid bid = new Bid(item, janeroe, new BigDecimal(2 + i));
item.getBids().add(bid);
em.persist(bid);
}
item = new Item("Item Three", CalendarUtil.AFTER_TOMORROW.getTime(), janeroe);
em.persist(item);
itemIds[2] = item.getId();
category.getItems().add(item);
item.getCategories().add(category);
category = new Category("Category Three");
em.persist(category);
categoryIds[2] = category.getId();
tx.commit();
em.close();
FetchTestData testData = new FetchTestData();
testData.items = new TestData(itemIds);
testData.users = new TestData(userIds);
return testData;
}
Aggregations