views:

81

answers:

1

Let's say i have two tables in db: Car and Part. Car owns arbitrialy number of parts.

Because i use EJB 3.0 i have entity beans for Car and Part and Car entity bean contains list of Part objects.

I want to save new Part to db and right after that fetch from db all Cars. I exepect Part i've just added to be amongst parts associated with fetched Cars. But it is not.

I do persist and find in single transaction so that's the problem i guess. How can i save something to db and right after calling persist on entityManager fetch it from db?

+1  A: 

Try to use EntityManager's flush method between persisting Part and fetching Car entities.

grigory
I tried this but to no avail... I still can't newly added fetch car entities.
mgamer
you should post your code then.
grigory