views:

30

answers:

1

hi, I'm using spring mvc 3.0 with eclipselink and jpa and I'm experiencing following issue: I have this field in my app:

@OneToMany(mappedBy = "stadium")
private Set<FootballMatch> footballMatches = new HashSet<FootballMatch>();

when there is triggered some action that adds new items into set via Set.add(), the changes doesn't show up in the browser, althought there are new rows in the database. When I clear the browser cache, nothing happens. I have discovered that a way how to force load new values is to redeploy the app, even without change of single line. So the app is returning old values, caching it somewhere. How do I force it to load allways updated values? I was thinking of something like getLastModified(), but I don't know where should I implement it.

+1  A: 

Since it is a bidirectional relationship, ensure that you are setting both sides of the relationship.

See, http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Object_corruption.2C_one_side_of_the_relationship_is_not_updated_after_updating_the_other_side

Also ensure you are changing, merging, committing the correct objects.

Try using EntityManager.refresh() to refresh the object, do you get the updated values? If you do not, then your database does not have the data.

Are you caching the EntityManager in your application? If you have an old EntityManager around it will not see new changes. Normally a new EntityManager should be created for each request/transaction.

EclipseLink maintains an object cache by default, this can be disabled using the persistence.xml property, "eclipselink.caching.shared"="false"

See, http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching

James
`"eclipselink.caching.shared"="false"` worked
coubeatczech
@coubeatchzech You have another problem somewhere, it should work with the cache enabled IMO.
Pascal Thivent