title: Persisting objects with Realm (error: Changing Realm data can only be done from inside a transaction)
body: <p>I am having difficulties getting Realm to work.</p>
  
  <pre><code>RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build();
  Realm.setDefaultConfiguration(realmConfig);
  Realm realm = Realm.getDefaultInstance();
  
  MyObjectExtendingRealmObject myObject = new MyObjectExtendingRealmObject("John");
  realm.beginTransaction();
  realm.copyToRealm(myObject);
  realm.commitTransaction();
  </code></pre>
  
  <p>Error:  java.lang.IllegalStateException: Changing Realm data can only be done from inside a transaction</p>
  
  <p>Call me crazy but aren't I doing the data persistence inside the transaction, which is exactly how it's done in the docs? See the example using <code>copyToRealm</code> here: <a href="https://realm.io/docs/java/latest/#creating-objects" rel="noreferrer">https://realm.io/docs/java/latest/#creating-objects</a></p>
  
  <p>What am I doing wrong?</p>
  
  <p>Edit: What, Realm doesn't support autoincrementing primary key ids? Dealbreaker for me. I'll leave this question up in case it helps others though.</p>
  
  <p>Edit: My class</p>
  
  <pre><code>public class MyObjectExtendingRealmObject extends RealmObject {
      private String name;
  
      public MyObjectExtendingRealmObject() {
  
      }
  
      public MyObjectExtendingRealmObject(String name) {
          this.name = name;
      }
  
      public String getName() {
          return this.name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>