EntityManager does not update on flush()

Posted by Sara on Stack Overflow See other posts from Stack Overflow or by Sara
Published on 2010-06-02T15:00:40Z Indexed on 2010/06/02 15:04 UTC
Read the original article Hit count: 223

Java EJB's EntityManager does not update data from a Consumer.

A Consumer logs into a shop, buys some stuff and wants to look at his shopping-history. Everything is displayed but his last purchase. If he logs out and in, it shows.

I have used JPA to persist buys/purchases (that are mapped to the Consumer)to DB. It seems like purchases from this session can't be detected.

Code:

public Buys buyItem(Consumer c, int amount) { Buys b = new Buys(); b.setConsumerId(c); b.setContent("DVD"); b.setPrice(amount); em.persist(b); em.flush(); return b; }

public Collection getAllBuysFromUser(Consumer consumer) { Collection collection = consumer.getBuysCollection(); return collection; }

Help!? Flush does not do the trick...

© Stack Overflow or respective owner

Related posts about jpa

Related posts about entity-relationship