[jboss-user] [EJB 3.0] - Extended Pers.Context and getResultList -> old data
bfo81
do-not-reply at jboss.com
Tue Aug 8 09:13:53 EDT 2006
I got a list of Person entities, e.g.
anonymous wrote : Doe, John
| Miller, Pete
| Sixpack, John
They are stored in a database and represented in a java.util.List(Person).
Ok, now I edit "Sixpack, John" to "Fivepack, John". The List gets updated like this:
persons = em.createQuery("from Person order by Name").getResultList();
Now there are two scenarios, depending on how the EntityManager got injected:
1.
@PersistenceContext
| private EntityManager em;
The list now is:
anonymous wrote : Doe, John
| Fivepack, John
| Miller, Pete
This is correct.
2.
@PersistenceContext(type=EXTENDED)
| private EntityManager em;
The list now is:
anonymous wrote : Doe, John
| Sixpack, John
| Miller, Pete
The list has the right order (due to the database query) BUT the editied Person still is Sixpack, instead of Fivepack. Why? Cause in the extended PersistenceContext the entity remains managed and so its properties don't get updated after hitting the database.
If I would want to have a list with updated names I'd have to call
//after getResultList()
| for(Person p: persons)
| em.refresh(p);
but that's idiotic since it causes an additional SELECT query for every Person entity.
QUESTION:
Is there any way to tell the EntityManager that he should check if managed entities have changed when retrieving a list of them by a query?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3963797#3963797
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3963797
More information about the jboss-user
mailing list