use of org.jpwh.model.advanced.ItemBidSummary in project microservices by pwillhan.
the class MappedSubselect method loadSubselectEntity.
@Test
public void loadSubselectEntity() throws Exception {
long ITEM_ID = storeItemAndBids();
UserTransaction tx = TM.getUserTransaction();
try {
tx.begin();
EntityManager em = JPA.createEntityManager();
{
ItemBidSummary itemBidSummary = em.find(ItemBidSummary.class, ITEM_ID);
// select * from (
// select i.ID as ITEMID, i.ITEM_NAME as NAME, ...
// ) where ITEMID = ?
assertEquals(itemBidSummary.getName(), "AUCTION: Some item");
}
em.clear();
{
// Hibernate will synchronize the right tables before querying
Item item = em.find(Item.class, ITEM_ID);
item.setName("New name");
// No flush before retrieval by identifier!
// ItemBidSummary itemBidSummary = em.find(ItemBidSummary.class, ITEM_ID);
// Automatic flush before queries if synchronized tables are affected!
Query query = em.createQuery("select ibs from ItemBidSummary ibs where ibs.itemId = :id");
ItemBidSummary itemBidSummary = (ItemBidSummary) query.setParameter("id", ITEM_ID).getSingleResult();
assertEquals(itemBidSummary.getName(), "AUCTION: New name");
}
tx.commit();
em.close();
} finally {
TM.rollback();
}
}
Aggregations