problem saving embedded objects

52 views
Skip to first unread message

ms

unread,
Nov 10, 2010, 6:45:16 PM11/10/10
to OrientDB
hello,

persisting embedded lists (OType.EMBEDDEDLIST) seems to work well, but
when trying to persist embedded enums/objects i get the following
error:

java.lang.IllegalArgumentException: Property 'protocol' of type
'EMBEDDED' can't accept value of type: class
com.orientechnologies.orient.core.record.impl.ODocument
at
com.orientechnologies.orient.core.record.impl.ODocument.field(ODocument.java:
422)
at
com.orientechnologies.orient.core.record.impl.ODocument.field(ODocument.java:
359)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.toStream(OObjectSerializerHelper.java:
317)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.pojo2Stream(ODatabaseObjectTx.java:
250)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.save(ODatabaseObjectTx.java:
174)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.save(ODatabaseObjectTx.java:
151)
at
com.echelon.es.common.db.orient.InheritanceTest.create(InheritanceTest.java:
92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:
74)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:675)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:848)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:
125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:
109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1119)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:315)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:310)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:272)
at org.testng.SuiteRunner.run(SuiteRunner.java:221)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:945)
at org.testng.TestNG.runSuitesLocally(TestNG.java:884)
at org.testng.TestNG.run(TestNG.java:818)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:96)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:179)

i used the following schema and classes:


OClass account = database.getMetadata().getSchema()
.createClass( "Account",
database.getStorage().addCluster( "account",
OStorage.CLUSTER_TYPE.PHYSICAL ) );
account.createProperty( "id", OType.INTEGER );
account.createProperty( "birthDate", OType.DATE );
account.createProperty( "binary", OType.BINARY );

account.createProperty( "lonStrings", OType.EMBEDDEDLIST, s );
OClass e =
database.getMetadata().getSchema().createClass( "InterfaceEProtocol" );
account.createProperty( "protocol", OType.EMBEDDED, e );

...


company = new Company( (int) i, "Microsoft" + i );
company.setEmployees( (int) (100000 + i) );
company.getAddresses().add( new Address( "Headquarter", redmond,
"WA 98073-9717" ) );
company.setUCPTuniqueId( new byte[] { 0x03, 0x00, 00, 0x1A, 0x7B,
0x62 } );
ELonString ls = new ELonString();
ls.setLonFormat( "bla" );
ls.setValue( "blubber" );
ls.setUnit( "blubb" );
List<ELonString> list = new ArrayList<ELonString>();
list.add( ls );
list.add( ls );
company.setLonStrings( list );
company.setProtocol( InterfaceEProtocol.I_PV_6 );

database.save( company );



public class Account {
private int id;
private String name;
private String surname;
private Date birthDate;
private float salary;
private List<Address> addresses = new ArrayList<Address>();
private List<ELonString> lonStrings = new ArrayList<ELonString>();
private InterfaceEProtocol protocol = null;
private transient boolean initialized = false;

public Account() {
}

public Account(int iId, String iName, String iSurname) {
this.id = iId;
this.name = iName;
this.surname = iSurname;
}

@OAfterDeserialization
public void initialize() {
initialized = true;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSurname() {
return surname;
}

public void setSurname(String surname) {
this.surname = surname;
}

public List<Address> getAddresses() {
return addresses;
}

public int getId() {
return id;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}

public float getSalary() {
return salary;
}

public void setSalary(float salary) {
this.salary = salary;
}

public List<ELonString> getLonStrings() {

return lonStrings;
}

public void setLonStrings(List<ELonString> lonStrings) {

this.lonStrings = lonStrings;
}

public InterfaceEProtocol getProtocol() {

return protocol;
}

public void setProtocol(InterfaceEProtocol protocol) {

this.protocol = protocol;
}

public boolean isInitialized() {
return initialized;
}

}


@XmlType(name = "Interface_eProtocol")
@XmlEnum
public enum InterfaceEProtocol {

@XmlEnumValue("IPv6")
I_PV_6("IPv6"),
@XmlEnumValue("IPv4")
I_PV_4("IPv4");
private final String value;

InterfaceEProtocol(String v) {
value = v;
}

public String value() {
return value;
}

public static InterfaceEProtocol fromValue(String v) {
for (InterfaceEProtocol c: InterfaceEProtocol.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}

}


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "E_LonString", propOrder = {
"value"
})
public class ELonString {

@XmlValue
protected String value;
@XmlAttribute(name = "LonFormat", required = true)
protected String lonFormat;
@XmlAttribute(name = "Unit")
protected String unit;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public String getLonFormat() {
return lonFormat;
}

public void setLonFormat(String value) {
this.lonFormat = value;
}

public String getUnit() {
return unit;
}

public void setUnit(String value) {
this.unit = value;
}

}


hope anyone can help,

thanks
markus

Luca Garulli

unread,
Nov 10, 2010, 8:42:39 PM11/10/10
to orient-database
Hi,
what version are you using? Please use the latest SVN trunk.

bye,
Lvc@

ms

unread,
Nov 11, 2010, 3:07:33 AM11/11/10
to OrientDB
i always use the most current svn trunk.
after an additional update it now works. great!

thanks,
markus

On 11 Nov., 02:42, Luca Garulli <l.garu...@gmail.com> wrote:
> Hi,
> what version are you using? Please use the latest SVN trunk.
>
> bye,
> Lvc@
>

ms

unread,
Nov 11, 2010, 6:15:37 PM11/11/10
to OrientDB
still having issues when retrieving enums (svn trunk at revision
1760):

accessing field values of objects returned by a query causes the
following errors
(see stack traces below for Enum access and List<Enum> access):

field of type Enum:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PASSED: create
PASSED: testCreate
FAILED: queryByBaseType
com.orientechnologies.orient.core.exception.OConfigurationException:
Can't retrieve pojo from the record Company@8:0{employees:
100000,ucpTuniqueId:[B@ba5c7a,id:
0,name:Microsoft0,surname:null,birthDate:null,salary:0.0,addresses:
[1],lonString:#6:0,lonStrings:[2],protocols:[2],protocol:#7:0}
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
268)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
245)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.query(ODatabaseObjectTx.java:
234)
at
com.echelon.es.common.db.orient.InheritanceTest.queryByBaseType(InheritanceTest.java:
124)
Caused by:
com.orientechnologies.orient.core.exception.OSchemaException: Can't
set the value '7:0' to the property 'protocol' for the pojo:
com.orientechnologies.orient.test.domain.business.Company@9446e4
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.setFieldValue(OObjectSerializerHelper.java:
152)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.fromStream(OObjectSerializerHelper.java:
188)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.stream2pojo(ODatabaseObjectTx.java:
255)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
265)
... 27 more
Caused by: java.lang.IllegalArgumentException: No enum const class
com.orientechnologies.orient.test.domain.business.InterfaceEProtocol.
7:0
at java.lang.Enum.valueOf(Enum.java:214)
at
com.orientechnologies.orient.core.metadata.schema.OType.convert(OType.java:
296)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.setFieldValue(OObjectSerializerHelper.java:
145)
... 30 more
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------


field of type List<Enum>:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2010-11-11 05:59:28:390 SEVE [ODatabaseObjectTx] Error on creating
object of class InterfaceEProtocol
->
com.orientechnologies.orient.core.entity.OEntityManager.createPojo(OEntityManager.java:
66)
->
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.newInstance(ODatabaseObjectTx.java:
78)
->
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
262)
->
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
245)
->
com.orientechnologies.orient.core.db.object.OLazyObjectIterator.next(OLazyObjectIterator.java:
56)
->
com.orientechnologies.orient.core.db.object.OLazyObjectIterator.next(OLazyObjectIterator.java:
46)
->
com.echelon.es.common.db.orient.InheritanceTest.queryByBaseType(InheritanceTest.java:
138)
-> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
->
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
->
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
-> java.lang.reflect.Method.invoke(Method.java:616)
->
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:
74)
-> org.testng.internal.Invoker.invokeMethod(Invoker.java:675)
-> org.testng.internal.Invoker.invokeTestMethod(Invoker.java:848)
-> org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
->
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:
125)
-> org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
-> org.testng.TestRunner.runWorkers(TestRunner.java:1119)
-> org.testng.TestRunner.privateRun(TestRunner.java:744)
-> org.testng.TestRunner.run(TestRunner.java:600)
-> org.testng.SuiteRunner.runTest(SuiteRunner.java:315)
-> org.testng.SuiteRunner.runSequentially(SuiteRunner.java:310)
-> org.testng.SuiteRunner.privateRun(SuiteRunner.java:272)
-> org.testng.SuiteRunner.run(SuiteRunner.java:221)
-> org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
-> org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
-> org.testng.TestNG.runSuitesSequentially(TestNG.java:945)
-> org.testng.TestNG.runSuitesLocally(TestNG.java:884)
-> org.testng.TestNG.run(TestNG.java:818)
-> org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:96)
-> org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:179)PASSED:
create
PASSED: testCreate
FAILED: queryByBaseType
com.orientechnologies.orient.core.exception.OConfigurationException:
Can't retrieve pojo from the record InterfaceEProtocol@
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
268)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
245)
at
com.orientechnologies.orient.core.db.object.OLazyObjectIterator.next(OLazyObjectIterator.java:
56)
at
com.orientechnologies.orient.core.db.object.OLazyObjectIterator.next(OLazyObjectIterator.java:
46)
at
com.echelon.es.common.db.orient.InheritanceTest.queryByBaseType(InheritanceTest.java:
138)
Caused by:
com.orientechnologies.orient.core.exception.ODatabaseException: Error
on creating object of class InterfaceEProtocol
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at
com.orientechnologies.common.log.OLogManager.error(OLogManager.java:
134)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.newInstance(ODatabaseObjectTx.java:
80)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:
262)
... 28 more
Caused by:
com.orientechnologies.orient.core.exception.OConfigurationException:
Error while creating new pojo of class 'InterfaceEProtocol'
at
com.orientechnologies.orient.core.entity.OEntityManager.createPojo(OEntityManager.java:
66)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.newInstance(ODatabaseObjectTx.java:
78)
... 29 more
Caused by: java.lang.InstantiationException:
com.orientechnologies.orient.test.domain.business.InterfaceEProtocol
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:325)
at
com.orientechnologies.orient.core.entity.OEntityManager.createPojo(OEntityManager.java:
63)
... 30 more
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

modified Inheritance test
schema + persist:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@Test
public void create() {

database.open( "admin", "admin" );

OClass account = database.getMetadata().getSchema()
.createClass( "Account",
database.getStorage().addCluster( "account",
OStorage.CLUSTER_TYPE.PHYSICAL ) );
account.createProperty( "id", OType.INTEGER );
account.createProperty( "birthDate", OType.DATE );
account.createProperty( "binary", OType.BINARY );
OClass s =
database.getMetadata().getSchema().createClass( "ELonString" );
s.createProperty( "value", OType.STRING );
s.createProperty( "lonFormat", OType.STRING ).setMandatory( true );
s.createProperty( "unit", OType.STRING );
// account.createProperty( "lonString", OType.EMBEDDED, s );
account.createProperty( "lonStrings", OType.EMBEDDEDLIST, s );
OClass e =
database.getMetadata().getSchema().createClass( "InterfaceEProtocol" );
// account.createProperty( "protocol", OType.EMBEDDED, e );
account.createProperty( "protocols", OType.EMBEDDEDLIST, e );

OClass c =
database.getMetadata().getSchema().createClass( "Company" ).setSuperClass( account );
c.createProperty( "ucpTuniqueId", OType.BINARY );

OClass profile = database.getMetadata().getSchema()
.createClass( "Profile",
database.getStorage().addCluster( "profile",
OStorage.CLUSTER_TYPE.PHYSICAL ) );
profile.createProperty( "nick",
OType.STRING ).setMin( "3" ).setMax( "30" ).createIndex( INDEX_TYPE.UNIQUE );
profile.createProperty( "name",
OType.STRING ).setMin( "3" ).setMax( "30" );
profile.createProperty( "surname",
OType.STRING ).setMin( "3" ).setMax( "30" );
profile.createProperty( "registeredOn",
OType.DATE ).setMin( "2010-01-01 00:00:00" );
profile.createProperty( "lastAccessOn",
OType.DATE ).setMin( "2010-01-01 00:00:00" );

startRecordNumber = database.countClusterElements("Company");

Company company;

for (long i = startRecordNumber; i < startRecordNumber +
TOT_RECORDS; ++i) {
company = new Company( (int) i, "Microsoft" + i );
company.setEmployees( (int) (100000 + i) );
company.getAddresses().add( new Address( "Headquarter", redmond,
"WA 98073-9717" ) );
company.setUCPTuniqueId( new byte[] { 0x03, 0x00, 00, 0x1A, 0x7B,
0x62 } );
ELonString ls = new ELonString();
ls.setLonFormat( "bla" );
ls.setValue( "blubber" );
ls.setUnit( "blubb" );
company.setLonString( ls );
List<ELonString> list = new ArrayList<ELonString>();
list.add( ls );
list.add( ls );
company.setLonStrings( list );
company.setProtocol( InterfaceEProtocol.I_PV_6 );
List<InterfaceEProtocol> lp = new ArrayList<InterfaceEProtocol>();
lp.add( InterfaceEProtocol.I_PV_4 );
lp.add( InterfaceEProtocol.I_PV_6 );
company.setProtocols( lp );
database.save( company );
}

database.close();
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

domain objects:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Account {
private int id;
private String name;
private String surname;
private Date birthDate;
private float salary;
private List<Address> addresses = new ArrayList<Address>();
private ELonString lonString = null;
private List<ELonString> lonStrings = new ArrayList<ELonString>();
private List<InterfaceEProtocol> protocols = new
ArrayList<InterfaceEProtocol>();
public ELonString getLonString() {

return lonString;
}

public void setLonString(ELonString lonString) {

this.lonString = lonString;
}

public List<ELonString> getLonStrings() {

return lonStrings;
}

public void setLonStrings(List<ELonString> lonStrings) {

this.lonStrings = lonStrings;
}

public List<InterfaceEProtocol> getProtocols() {

return protocols;
}

public void setProtocols(List<InterfaceEProtocol> protocols) {

this.protocols = protocols;
}

public InterfaceEProtocol getProtocol() {

return protocol;
}

public void setProtocol(InterfaceEProtocol protocol) {

this.protocol = protocol;
}

public boolean isInitialized() {
return initialized;
}

}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Company extends Account {

private int employees;
protected byte[] ucpTuniqueId;

public Company() {

}

public Company(int iId, String iName) {

super( iId, iName, null );
}

public int getEmployees() {

return employees;
}

public void setEmployees(int employees) {

this.employees = employees;
}

public byte[] getUCPTuniqueId() {

return ucpTuniqueId;
}

public void setUCPTuniqueId(byte[] value) {

this.ucpTuniqueId = ((byte[]) value);
}

}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@XmlType(name = "Interface_eProtocol")
@XmlEnum
public enum InterfaceEProtocol {

@XmlEnumValue("IPv6")
I_PV_6("IPv6"),
@XmlEnumValue("IPv4")
I_PV_4("IPv4");
private final String value;

InterfaceEProtocol(String v) {
value = v;
}

public String value() {
return value;
}

public static InterfaceEProtocol fromValue(String v) {
for (InterfaceEProtocol c: InterfaceEProtocol.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}

}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "E_LonString", propOrder = {
"value"
})
public class ELonString {

@XmlValue
protected String value;
@XmlAttribute(name = "LonFormat", required = true)
protected String lonFormat;
@XmlAttribute(name = "Unit")
protected String unit;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public String getLonFormat() {
return lonFormat;
}

public void setLonFormat(String value) {
this.lonFormat = value;
}

public String getUnit() {
return unit;
}

public void setUnit(String value) {
this.unit = value;
}

}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

thanks markus
Reply all
Reply to author
Forward
0 new messages