orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.74k stars 870 forks source link

CREATE VERTEX fails, INSERT INTO works #6261

Closed lucafrosini closed 8 years ago

lucafrosini commented 8 years ago

Expected behavior and actual behavior

com.orientechnologies.orient.core.exception.OValidationException: The field 'MyVertex.test' has been declared as EMBEDDED but an incompatible type is used. Value: {name=Luca} Storage URL="plocal:/home/lucafrosini/workspace/orientdb-community-2.2.0/databases/test" [ONetworkProtocolHttpDb]

Steps to reproduce the problem

CREATE CLASS MyVertex EXTENDS V
CREATE CLASS MyEmbedded
CREATE PROPERTY MyVertex.test EMBEDDED MyEmbedded
CREATE PROPERTY MyEmbedded.name STRING

These queries fail:

CREATE VERTEX MyVertex SET test = {"name":"Luca"}
CREATE VERTEX MyVertex CONTENT { "test" : {"name":"Luca"} }

This query works instead:

INSERT INTO MyVertex SET test = {"name":"Luca"}

Important Questions

Runninng Mode

lucafrosini commented 8 years ago

I tryed to reproduce the problem using Java classes. I obtain a different exception.

OrientGraphFactory factory = new OrientGraphFactory( "remote:localhost/testdb", "admin", "admin").setupPool(1, 10);

OrientGraphNoTx orientGraph = factory.getNoTx();
OMetadata oMetadata = orientGraph.getRawGraph().getMetadata();
OSchema oSchema = oMetadata.getSchema();

OrientVertexType myVertexType = orientGraph.createVertexType("MyVertex");
OClass myEmbedded = oSchema.createClass("MyEmbedded");
myEmbedded.createProperty("name", OType.STRING);
myVertexType.createProperty("test", OType.EMBEDDED, myEmbedded);

ODocument embeddedDocument = new ODocument();
embeddedDocument.field("name", "Luca");

OrientVertex orientVertex = orientGraph.addVertex("class:MyVertex");
orientVertex.setProperty("test", embeddedDocument, OType.EMBEDDED);
orientVertex.save();

orientGraph.shutdown();

The following exception occurs on

orientVertex.setProperty("test", embeddedDocument, OType.EMBEDDED);
com.orientechnologies.orient.core.exception.OValidationException: The field 'MyVertex.test' has been declared as EMBEDDED with linked class 'MyEmbedded' but the record has no class
    Storage URL="plocal:/home/lucafrosini/workspace/orientdb-community-2.2.0/databases/testdb"
    Storage URL="plocal:/home/lucafrosini/workspace/orientdb-community-2.2.0/databases/testdb"
    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:526)
    at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.throwSerializedException(OChannelBinaryAsynchClient.java:431)
    at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.handleStatus(OChannelBinaryAsynchClient.java:382)
    at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:264)
    at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:152)
    at com.orientechnologies.orient.client.remote.OStorageRemote.beginResponse(OStorageRemote.java:2204)
    at com.orientechnologies.orient.client.remote.OStorageRemote.beginResponse(OStorageRemote.java:2199)
    at com.orientechnologies.orient.client.remote.OStorageRemote$7.execute(OStorageRemote.java:680)
    at com.orientechnologies.orient.client.remote.OStorageRemote$7.execute(OStorageRemote.java:652)
    at com.orientechnologies.orient.client.remote.OStorageRemote.networkOperation(OStorageRemote.java:160)
    at com.orientechnologies.orient.client.remote.OStorageRemote.updateRecord(OStorageRemote.java:652)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeSaveRecord(ODatabaseDocumentTx.java:2021)
    at com.orientechnologies.orient.core.tx.OTransactionNoTx.saveRecord(OTransactionNoTx.java:186)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:2529)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:99)
    at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1817)
    at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1808)
    at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:334)
    at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:316)
    at com.tinkerpop.blueprints.impls.orient.OrientElement.setProperty(OrientElement.java:228)
    at org.gcube.informationsystem.resourceregistry.resources.impl.ContextManagementImplMyTest.embeddedTest(ContextManagementImplMyTest.java:116)
    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:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
luigidellaquila commented 8 years ago

Hi @lucafrosini

Thank you very much for reporting, I just fixed it in develop branch (next v 2.2.1).

Now INSERT and CREATE VERTEX work in the same way:

the following have the same effect:

CREATE VERTEX MyVertex SET test = {"name":"Luca"}
INSERT INTO MyVertex SET test = {"name":"Luca"}

But for the following, you have to explicitly declare the inner field as embedded, using @type=d and the class name:

CREATE VERTEX MyVertex CONTENT { "test" : {"@type":"d", "@class":"MyEmbedded", "name":"Luca"} }
INSERT INTO MyVertex CONTENT { "test" : {"@type":"d", "@class":"MyEmbedded", "name":"Luca"} }

Thanks

Luigi

lucafrosini commented 8 years ago

Thank you very much