You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is Issue 154 moved from a Google Code project.
Added by 2010-11-22T12:15:51.000Z by m.siemen...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-Medium, v0.9.24
Original description
<b>What steps will reproduce the problem?</b>
1. declare a member of type object/enum in a domain class
2. create a schema property of type EMBEDDED for this member
3. try to save/retrieve it from orient database
What is the expected output?
objects and enums can be saved/retrieved from orientdb
What do you see instead?
exceptions when saving retrieving objects/enums
below is a patch that fixes the problem. see also discussion
titled "problem saving embedded objects re-introduced again"
a testcase is also attached.
regards,
markus
Index: core/src/main/java/com/orientechnologies/orient/core/metadata/
schema/OType.java
===================================================================
--- core/src/main/java/com/orientechnologies/orient/core/metadata/
schema/OType.java (revision 1815)
+++ core/src/main/java/com/orientechnologies/orient/core/metadata/
schema/OType.java (working copy)
@@ -25,6 +25,7 @@
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.record.ORecord;
+import com.orientechnologies.orient.core.record.impl.ODocument;
/**
* Generic representation of a type.<br/>
@@ -52,7 +53,7 @@
},
BINARY("Binary", 8, false, false, 8, new Class<?>[] { Array.class },
new Class<?>[] { Array.class }) {
},
- EMBEDDED("Embedded", 9, true, false, 8, new Class<?>[]
{ Object.class }, new Class<?>[] {}) {
+ EMBEDDED("Embedded", 9, true, false, 8, new Class<?>[]
{ Object.class }, new Class<?>[] { Object.class }) {
},
EMBEDDEDLIST("List", 10, true, false, 8, new Class<?>[]
{ List.class }, new Class<?>[] { Collection.class, Array.class }) {
},
@@ -290,6 +291,9 @@
return iValue;
if (iTargetClass.isEnum()) {
+ if (iValue instanceof ODocument) {
+ return Enum.valueOf((Class<Enum>) iTargetClass, (String)
((ODocument) iValue).field( "name" ) );
+ }
if (iValue instanceof Number)
return ((Class<Enum>) iTargetClass).getEnumConstants()[((Number)
iValue).intValue()];
Index: core/src/main/java/com/orientechnologies/orient/core/db/
ODatabasePojoAbstract.java
===================================================================
--- core/src/main/java/com/orientechnologies/orient/core/db/
ODatabasePojoAbstract.java (revision 1815)
+++ core/src/main/java/com/orientechnologies/orient/core/db/
ODatabasePojoAbstract.java (working copy)
@@ -23,6 +23,7 @@
import com.orientechnologies.orient.core.command.OCommandRequest;
import
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
+import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import
com.orientechnologies.orient.core.db.object.OObjectNotManagedException;
import
com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.hook.ORecordHook;
@@ -259,10 +260,20 @@
if (record.getInternalStatus() == STATUS.NOT_LOADED)
record.load();
- pojo = newInstance(record.getClassName());
+ boolean isEnum = false;
+ Class<?> javaClass = null;
+ if (this instanceof ODatabaseObject
+ && (javaClass = ((ODatabaseObject)
this).getEntityManager().getEntityClass( record.getClassName() )) !=
null
+ && (isEnum = Enum.class.isAssignableFrom( javaClass ))) {
+ pojo = (T) Enum.valueOf( (Class<Enum>) javaClass, (String)
record.field( "name" ) );
+ } else {
+ pojo = newInstance(record.getClassName());
+ }
registerPojo(pojo, record);
- stream2pojo(record, pojo, iFetchPlan);
+ if (!isEnum) {
+ stream2pojo(record, pojo, iFetchPlan);
+ }
} catch (Exception e) {
throw new OConfigurationException("Can't retrieve pojo from the
record " + record, e);
Index: core/src/main/java/com/orientechnologies/orient/core/
serialization/serializer/object/OObjectSerializerHelper.java
===================================================================
--- core/src/main/java/com/orientechnologies/orient/core/serialization/
serializer/object/OObjectSerializerHelper.java (revision 1815)
+++ core/src/main/java/com/orientechnologies/orient/core/serialization/
serializer/object/OObjectSerializerHelper.java (working copy)
@@ -245,6 +245,9 @@
} else if (type.isEnum()) {
String enumName = ((ODocument) iLinked).field(iFieldName);
+ if (null == enumName) {
+ enumName = ((ODocument) iLinked).field( "name" );
+ }
@SuppressWarnings("rawtypes")
Class<Enum> enumClass = (Class<Enum>) type;
fieldValue = Enum.valueOf(enumClass, enumName);
===================================================================
The text was updated successfully, but these errors were encountered:
This is Issue 154 moved from a Google Code project.
Added by 2010-11-22T12:15:51.000Z by m.siemen...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).
Original labels: Type-Defect, Priority-Medium, v0.9.24
Original description
The text was updated successfully, but these errors were encountered: