I have an owner (Category) and a customer (Forum) entities designed this way:
Category
...
@OneToMany( fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "category" )
@OrderBy( "position" )
private List<Forum> forums;
...
Forum
...
@ManyToOne
@JoinColumn( name = "category" )
private Category category;
private Integer position;
...
Somewhere in my webapp, I display the forums list, and I execute some business action on one of them, for example changing its position.
My issue is that the change is well persisted in the database, but is not reflected on the OneToMany mapped collection. Thus when I refresh the page that displays the list, it doesn't show the new position but the previous one.
The code I use to update an element's position is equivalent to a simple em.merge( forum )
. I read in many topics that I should "manually manage" the bidirectionnal relationship, otherwise I would face this kind of issues. Here are my two questions :
- I tried on both EclipseLink and Hibernate, and while it works well with Hibernate (list is updated), it doens't in EclipseLink. Is it related to some caching mode difference?
- How should I manually notice my list that one of its element's property has changed (e.g. the position property of a forum in the forums list) ?
[EDIT] I read this topic and I feel my issue is related to my forum being updated by a different session from the one being used to fetch the list. Am I understanding it right? If yes, how to correctly manage that case?