Wrapping an ODocument causes fields not to be saved

41 views
Skip to first unread message

Alberto Siena

unread,
May 14, 2012, 10:38:17 AM5/14/12
to orient-...@googlegroups.com
Hi

After struggling a  lot I found that wrapping an ODocument into another class causes fields not to be saved as I expected. Consider for example the two functions and the DummyRecord class reported below; to me they seem to do the same thing, but the output is different:

> select from Source

---+---------+--------------------
  #| RID     |links               
---+---------+--------------------
  0|    #21:4|{linkName:[1]}      
  1|    #21:5|null                
---+---------+--------------------

So what's wrong with wrapping an ODocument like DummyRecord does? Is there any caching issues I should consider? (I'm using rc9)

Thanks

Alberto


public void test1() throws Exception
{
DummyRecord target = new DummyRecord( "Target" );
target.save();
DummyRecord source = new DummyRecord( "Source" );
target.save();
ODocument out = source.getODocument().field( "links", OType.EMBEDDED );
if( out == null )
{
source.getODocument().field( "links", new ODocument(), OType.EMBEDDED );
}
out = source.getODocument().field( "links" );
List<ODocument> links = out.field( "linkName", OType.EMBEDDED );
if( links == null )
{
links = new ArrayList<ODocument>();
out.field( "linkName", links, OType.LINKLIST );
}
links.add( target.getODocument() );
source.save();
}

public void test2() throws Exception
{
ODocument target = new ODocument( "Target" );
ODocument source = new ODocument( "Source" );
ODocument out = source.field( "links", OType.EMBEDDED );
if( out == null )
{
source.field( "links", new ODocument(), OType.EMBEDDED );
}
out = source.field( "links" );
List<ODocument> links = out.field( "linkName", OType.EMBEDDED );
if( links == null )
{
links = new ArrayList<ODocument>();
out.field( "linkName", links, OType.LINKLIST );
}
links.add( target );
source.save();
}

public class DummyRecord
{
ODocument doc;
public DummyRecord( String cname ){
doc = new ODocument( cname );
doc.field( "links", new ODocument(), OType.EMBEDDED );
doc.save();
}
public ODocument getODocument(){
return this.doc;
}
public void save() {
this.doc.save();
}
}

Alberto Siena

unread,
May 15, 2012, 9:18:54 AM5/15/12
to orient-...@googlegroups.com
For those who may be interested: removing the doc.save(); in the DummyRecord constructor makes it work.

Now my question is: why???

Luca Garulli

unread,
May 15, 2012, 12:42:33 PM5/15/12
to orient-...@googlegroups.com
Hi Alberto,
don't know why the first save makes a mess. Could you open an issue for that?

Lvc@

Alberto Siena

unread,
May 16, 2012, 3:23:09 AM5/16/12
to orient-...@googlegroups.com
Sure
Reply all
Reply to author
Forward
0 new messages