title: ORMLite and adding an existing persisted entity to a foreign field collection
body: <p>I have a <code>Language</code> entity with a ForeignCollection of <code>Country</code> entities:</p>
  
  <pre><code>@ForeignCollectionField(eager = false, foreignFieldName = "language")
  public ForeignCollection&lt;Country&gt; countries;
  </code></pre>
  
  <p>I create a country, say representing France, in my database. Later, I retrieve it by querying for its id and I want to add this to a Language's foreign collection of countries:</p>
  
  <pre><code>Country country = dbHelper.getCountryDao().queryForId(countryId);
  if (country != null) {
      country.language = language;    
      ForeignCollection&lt;Country&gt; countries = language.countries;
      if (countries == null) {
          countries = dbHelper.getLanguageDao().getEmptyForeignCollection("countries");
      }
      countries.add(country); // Illegal state exception thrown here
      language.countries = countries;
      dbHelper.getLanguageDao().create(language);
  }
  </code></pre>
  
  <p>However, the marked line <code>countries.add(country)</code> causes an illegal state exception to be thrown:</p>
  
  <blockquote>
    <p>01-27 13:39:19.112: E/AndroidRuntime(15614): Caused by:
    java.sql.SQLException: inserting to database failed: INSERT INTO
    <code>countries</code> (<code>identifier</code> ,<code>name</code> ,<code>language_id</code> ) VALUES (?,?,?)
    01-27 13:39:19.112: E/AndroidRuntime(15614):  at
    com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)</p>
  </blockquote>
  
  <p>Why does <code>.add()</code> trigger the recreation of an entity existing in the database and the internal DAO? And what should I be doing instead?</p>