Hello,

I am working on a web project where the underlying database can get updated
by an other systems. My scenario is as follows: I have the following tables;
USERS and HOBBY. I mapped a User object with the USERS table and a Hobby
object with the HOBBY table. A User can have one ore more Hobby so I have a
List<Hobby> in User mapped using the annotation @OneToMany. A Hobby can be
linked with only one User so I use the annotation @ManyToOne from Hobby.

My problem, as indicated int he first sentence, is that the HOBBY table may
be updated through another system (outside of JPA world). When this happens,
when I call User user = em.find(1) the object I get does not reflect the
real data there is in the the database but the same data I had for this User
as it was when I last interacted with the EntityManager for this particular
user.

In other words, if User 1 had four Hobby and the other system add another
two Hobby to User 1 then when I go to the screen that shows me all Hobby for
User 1 I get four because last time I got User 1 using JPA this User had
four Hobby!

I went to the Java API for the EntityManager and I found two methods:

*refresh(java.lang.Object entity) *
/Refresh the state of the instance from the database, overwriting changes
made to the entity, if any./

*flush() *
/Synchronize the persistence context to the underlying database./

I tried them both but none are working for me. Does anyone know what I am
doing wrong?
  



--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Why-is-EntityManager-refresh-not-working-for-me-tp7586653.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to