Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate: Removing item from a List does not persist
    primarykey
    data
    text
    <p>I am having trouble when removing an item from a list. The list is defined in a superclass, but the Hibernate annotations are applied to property accessors in a subclass. There are two methods in the superclass that manipulate the list. The "add" method works fine, but the "remove" does not persist changes. I have checked my Cascade settings, and I seem to have things correct. Am I doing something that is impossible. If not, am I doing something incorrectly? </p> <p>Here are my classes:</p> <pre><code>@Entity abstract class Temporal&lt;T&gt; { @Id @GeneratedValue private Long id; @Version private Integer version = null; @Transient protected List&lt;T&gt; content = new ArrayList&lt;T&gt;(); public void remove(T value) { // business logic ... content.remove(value); } public void add(T value) { // business logic ... content.add(value); } } @Entity @AccessType("property") class TemporalAsset extends Temporal&lt;Asset&gt; { @OneToMany(cascade = CascadeType.ALL, mappedBy = "temporal") public List&lt;Asset&gt; getContent() { return super.content; } protected void setContent(List&lt;Asset&gt; list) { super.content = list; } } </code></pre> <p>I use an instance of the TemporalAsset class as follows (note that I am only use the "refresh" method to demonstrate the behavior. The list does not persist correctly even if I flush or close the session and open a new session): </p> <pre><code>temporalAsset.add(value1); temporalAsset.getContent().size() == 1; // true session.update(temporalAsset); session.refresh(temporalAsset); temporalAsset.getContent().size() == 1; // true temporalAsset.remove(value1); temporalAsset.getContent().size() == 0; // true session.update(temporalAsset); session.refresh(temporalAsset); temporalAsset.getContent().size() == 0; // false, its 1 </code></pre> <p>Thanks.</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.
    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