Spring MVC 3.0 缓存
我正在将 spring mvc 3.0 与 eclipselink 和 jpa 一起使用,并且遇到以下问题:我的应用程序中有此字段:
@OneToMany(mappedBy = "stadium")
private Set<FootballMatch> footballMatches = new HashSet<FootballMatch>();
当触发某些操作时,通过 Set.add() 将新项目添加到集合中code>,尽管数据库中有新行,但更改不会显示在浏览器中。当我清除浏览器缓存时,什么也没有发生。我发现强制加载新值的一种方法是重新部署应用程序,即使不更改单行。因此应用程序返回旧值,并将其缓存在某处。如何强制它加载始终更新的值? 我正在考虑类似 getLastModified()
的东西,但我不知道应该在哪里实现它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它是双向关系,因此请确保您正在设置关系的双方。
看,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Object_corruption。 2C_one_side_of_the_relationship_is_not_updated_after_updating_the_other_side
还要确保您正在更改、合并、提交正确的对象。
尝试使用 EntityManager.refresh() 刷新对象,您是否获得更新的值?如果不这样做,则您的数据库中没有该数据。
您是否在应用程序中缓存 EntityManager?如果您周围有一个旧的 EntityManager,它将看不到新的更改。通常应该为每个请求/事务创建一个新的EntityManager。
EclipseLink 默认情况下维护一个对象缓存,可以使用 persistence.xml 属性禁用它,
"eclipselink.caching.shared"="false"
看,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching
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