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();
}
}