Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle App Engine - JDODetachedFieldAccessException
    primarykey
    data
    text
    <p>I'm pretty new to JPA/JDO and the whole objectdb world.</p> <p>I have an entity with a set of strings, looks a bit like:</p> <pre><code>@Entity public class Foo{ @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Key id; private Set&lt;String&gt; bars; public void setBars(Set&lt;String&gt; newBars){ if(this.bars == null) this.bars = new HashSet&lt;String&gt;; this.bars = newBars; } public Set&lt;String&gt; getBars(){ return this.bars; } public void addBar(String bar){ if(this.bars == null) this.bars = new HashSet&lt;String&gt;; this.bars.add(bar); } } </code></pre> <p>Now, in another part of the code, I'm trying to do something like this:</p> <pre><code>EntityManager em = EMF.get().createEntityManager(); Foo myFoo = em.find(Foo.class, fooKey); em.getTransaction().begin(); myFoo.addBar(newBar); em.merge(myFoo); em.getTransaction().commit(); </code></pre> <p>When, of course, newBar is a String.</p> <p>But, what I get is:</p> <pre><code>javax.jdo.JDODetachedFieldAccessException: You have just attempted to access field "bars" yet this field was not detached when you detached the object. Either dont access this field, or detach it when detaching the object. </code></pre> <p>I've searched for an answer, but I couldn't find one.</p> <p>I've seen someone ask about a Set of strings, and he was told to add an @ElementCollection notation. </p> <p>I tried that, but I got an error about the String class Metadata (I don't really understand what it means.)</p> <p>I would really appreciate some help on this thing, even a good reference to someone explaining this (in simple English).</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.
    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