Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA - How to update a collection in a bi-directionnal OneToMany/ManyToOne relation
    primarykey
    data
    text
    <p>I have an owner (Category) and a customer (Forum) entities designed this way:</p> <p><strong>Category</strong></p> <pre><code>... @OneToMany( fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "category" ) @OrderBy( "position" ) private List&lt;Forum&gt; forums; ... </code></pre> <p><strong>Forum</strong></p> <pre><code>... @ManyToOne @JoinColumn( name = "category" ) private Category category; private Integer position; ... </code></pre> <p>Somewhere in my webapp, I display the forums list, and I execute some business action on one of them, for example changing its position.</p> <p>My issue is that the change is well persisted in the database, but is <strong>not reflected on the OneToMany mapped collection</strong>. Thus when I refresh the page that displays the list, it doesn't show the new position but the previous one.</p> <p>The code I use to update an element's position is equivalent to a simple <code>em.merge( forum )</code>. 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 :</p> <ul> <li>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?</li> <li>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) ?</li> </ul> <p><strong>[EDIT] I read <a href="https://stackoverflow.com/questions/4416359/entitymanager-doesnt-see-changes-made-in-other-transactions?lq=1">this topic</a> 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?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload