openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <>
Subject Re: Why is EntityManager refresh(...) not working for me?
Date Thu, 22 May 2014 15:48:28 GMT
If you are calling EM.refresh() directly, you should get a refreshed
version of the entity that is committed to the database.  Any relationships
to other entities will only be refreshed if you are using the
CascadeType.REFRESH (or ALL) specified on your relationship [1].  The other
thing that can affect refreshing is the use of the L2 data cache.  Any
chance you have that enabled?  A copy of your persistence.xml is always
helpful with understanding your environment.  Thanks.


On Thu, May 22, 2014 at 10:22 AM, sim085 <> wrote:

> 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:
> Sent from the OpenJPA Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message