title: OrientDB - exception when I try to save an embeddedlist
body: <p>I have a class named <code>CalculationFunctionGroup</code> where I have an attribute like this:</p>
  
  <pre><code>List&lt;CalculationFunction&gt; functions;
  </code></pre>
  
  <p>on my OrientDB I have a table named <code>CalculationFunctionGroup</code> with a property <code>functions</code> definaed as EMBEDDEDLIST and linked class <code>CalculationFunction</code>.</p>
  
  <p>When I try to save an object of type CalculationFunctionGroup an exception raises.</p>
  
  <p>The exception tell me:</p>
  
  <blockquote>
    <p>The field 'functions' has been declared as EMBEDDEDLIST with linked class 'CalculationFunction' but the record has no class.</p>
  </blockquote>
  
  <p>I try to find this exception in OrientDB source code, and I find this:</p>
  
  <p>There's a check in <code>ODocument</code> class in the method <code>validateEmbedded</code> where there are these code lines:</p>
  
  <pre><code>if (doc.getImmutableSchemaClass() == null)
        throw new OValidationException("The field '" + p.getFullName() + "' has been declared as " + p.getType()
            + " with linked class '" + embeddedClass + "' but the record has no class");
  </code></pre>
  
  <p>So, I don't understand how can I valued the immutableschemaclass property.</p>
  
  <p>Where I try to set my field value from Java, I use this command line:</p>
  
  <pre><code>this.data.field(fieldName, value, OType.EMBEDDEDLIST);
  </code></pre>
  
  <p>where <code>data</code> is my <code>ODocument</code> instance, <code>fieldName</code> is <code>functions</code>, value is my <code>List</code> of <code>CalculationFunction</code> and <code>OType</code> is <code>EMBEDDEDLIST</code>.</p>
  
  <p>Used Orient version is 2.2.0</p>
  
  <p><strong>EDIT #1</strong></p>
  
  <p>I try this after Alessandro Rota answer, but the error is the same:</p>
  
  <pre><code>ODocument myEntity = new ODocument("CalculationFunctionGroup");
  myEntity.field("referenceItem", object.getReferenceItem().getData());
  db.save(myEntity);
  db.commit();
  </code></pre>
  
  <p>In this code snippet I've changed the nature of my objct (the original is a typied object as CalculationFunctionGroup and now is an ODocument). But the error is the same.</p>
  
  <p>Another try I've done, the ODocument <code>myEntity</code> has not attached functions (list of CalculationFunction) but the error raises too</p>
  
  <p><strong>EDIT #2</strong></p>
  
  <p>I've tried with code snippet of Alessandro Rota and works fine.</p>
  
  <p>But when I add as field of CalculationFunction a link field I've the same error! Why?</p>
  
  <p>If I add a link field instead of object.getData() with object.getRawField("@rid") it works fine too.</p>
  
  <p>I don't understand because raises that error message, and the reason of different behaviour when I use only @rid field instead complete object</p>
  
  <p><strong>EDIT #3</strong>
  Latest news: </p>
  
  <p>This is my test scenario:</p>
  
  <p>I have this table:</p>
  
  <p>CalculationFunction with these property (schemafull):</p>
  
  <p>referenceItem LINK
  functions EMBEDDEDLIST</p>
  
  <p>When I try to save, I write this code:</p>
  
  <pre><code>    ODocument myGroup = new ODocument("CalculationFunctionGroup");
      Object rid = null;
      if (object.getField("referenceItem") instanceof RegistryMetadata) {
          rid = ((RegistryMetadata)(object.getField("referenceItem"))).getRawField("@rid");
      } else if (object.getField("referenceItem") instanceof PayrollRegistryMetadata) {
          rid = ((PayrollRegistryMetadata)(object.getField("referenceItem"))).getRawField("@rid");
      } else if (object.getField("referenceItem") instanceof PreCalculationMetadata) {
          rid = ((PreCalculationMetadata)(object.getField("referenceItem"))).getRawField("@rid");
      } else if (object.getField("referenceItem") instanceof CalculationMetadata) {
          rid = ((CalculationMetadata)(object.getField("referenceItem"))).getRawField("@rid");
      }
  
      myGroup.field("referenceItem", rid, OType.LINK);
      myGroup.field("scenario", ((Scenario)object.getField("scenario")).getRawField("@rid"));
  
      List&lt;ODocument&gt; lstFunctions = new ArrayList&lt;ODocument&gt;();
      if (object.getField("functions") != null) {
          Iterable&lt;ODocument&gt; lstFun = (Iterable&lt;ODocument&gt;) object.getField("functions");
          Iterator&lt;ODocument&gt; itFun = lstFun.iterator(); 
          while(itFun.hasNext()) {
              ODocument currFun = itFun.next();
  
              ODocument oFun = new ODocument("CalculationFunction");
              oFun.field("name", currFun.field("name"));
              oFun.field("code", currFun.field("code"));
              oFun.field("language", currFun.field("language"));
  
              lstFunctions.add(oFun);
          }
      }
      myGroup.field("functions", lstFunctions, OType.EMBEDDEDLIST);
      myGroup.save();
  
      db.commit();
  </code></pre>
  
  <p>This code goes in error, but... If I write this:</p>
  
  <pre><code>    myGroup.field("referenceItem2", rid, OType.LINK);
  </code></pre>
  
  <p>The code works fine.</p>
  
  <p>The difference: referenceItem is a schemafull property, referenceItem2 is a schemaless field.</p>