Orientdb: Unable to create edge on STRICTMODE Class

Created on 6 Dec 2016  路  9Comments  路  Source: orientechnologies/orientdb

OrientDB Version, operating system, or hardware.

  • v2.2.13

Operating System

  • [x] Linux
  • [x] MacOSX

Expected behavior and actual behavior

I have a class with enabled STRICTMODE. Executing queries to create Edge on this class works without the strict mode, but with strict mode = true it fails.

Steps to reproduce the problem

There are 2 classes LeadYear and LeadMonth. LeadYear has Strict Mode enabled. We need to simply create an edge 'LeadCreatedMonth' from LeadYear to LeadMonth.

Class with STRICTMODE = false

orientdb {db=Customers}> info class LeadYear

CLASS 'LeadYear'
Records..............: 1
Super classes........: [V]
Default cluster......: leadyear (id=217)
Supported clusters...: leadyear(217), leadyear_1(218), leadyear_2(219), leadyear_3(220)
Cluster selection....: round-robin
Oversize.............: 0.0

PROPERTIES
+----+-------+-------+-----------------+---------+--------+--------+----+----+-------+-------+
|#   |NAME   |TYPE   |LINKED-TYPE/CLASS|MANDATORY|READONLY|NOT-NULL|MIN |MAX |COLLATE|DEFAULT|
+----+-------+-------+-----------------+---------+--------+--------+----+----+-------+-------+
|0   |value  |INTEGER|                 |true     |false   |true    |    |    |default|       |
|1   |account|LINK   |Account          |true     |false   |true    |    |    |default|       |
+----+-------+-------+-----------------+---------+--------+--------+----+----+-------+-------+
orientdb {db=Customers}> select from (select expand(classes) from metadata:schema) where name = 'LeadYear'

+----+--------+--------+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------------------------------------------------------------+
|#   |name    |overSize|abstract|shortName|strictMod|superClas|descripti|superClas|customFie|defaultCl|clusterSe|clusterId|properties                                                      |
+----+--------+--------+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------------------------------------------------------------+
|0   |LeadYear|0.0     |false   |         |false    |V        |         |[V]      |         |217      |round-...|[217,2...|[#3:603,{name:account,type:13,globalId:54,mandatory:true,read...|
+----+--------+--------+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------------------------------------------------------------+
1 item(s) found. Query executed in 0.002 sec(s).

Enabling STRICTMODE = true

orientdb {db=Customers}> alter class LeadYear STRICTMODE TRUE 
Class updated successfully.

orientdb {db=Customers}> select from (select expand(classes) from metadata:schema) where name = 'LeadYear'

+----+--------+--------+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------------------------------------------------------------+
|#   |name    |overSize|abstract|shortName|strictMod|superClas|descripti|superClas|customFie|defaultCl|clusterSe|clusterId|properties                                                      |
+----+--------+--------+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------------------------------------------------------------+
|0   |LeadYear|0.0     |false   |         |true     |V        |         |[V]      |         |217      |round-...|[217,2...|[#3:603,{name:account,type:13,globalId:54,mandatory:true,read...|
+----+--------+--------+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+----------------------------------------------------------------+

1 item(s) found. Query executed in 0.002 sec(s).

Creating new record in LeadYear

orientdb {db=Customers}> insert into LeadYear (value, account) values (2016, 25:1)
Inserted record 'LeadYear#218:0{value:2016,account:#25:1} v1' in 0.031000 sec(s).
orientdb {db=Customers}> select from LeadYear                                     

+----+------+--------+--------------------+------------------+--------------------+-----+-------+
|#   |@RID  |@CLASS  |in_LeadPurchasedYear|in_LeadCreatedYear|out_LeadCreatedMonth|value|account|
+----+------+--------+--------------------+------------------+--------------------+-----+-------+
|0   |#217:0|LeadYear|#253:0              |[]                |[#237:0,#237:1]     |2016 |#26:1  |
|1   |#218:0|LeadYear|                    |                  |                    |2016 |#25:1  |
+----+------+--------+--------------------+------------------+--------------------+-----+-------+

Just in case reloading schema

orientdb {db=Customers}> reload schema
reloading database schema...
Done.
orientdb {db=Customers}> 

Attempting to create an edge

orientdb {db=Customers}> create edge LeadCreatedMonth from #218:0 to #229:2
Error: com.orientechnologies.orient.core.exception.OValidationException: Found additional field 'out_LeadCreatedMonth'. It cannot be added because the schema class 'LeadYear' is defined as STRICT
    DB name="Customers"
    DB name="Customers"

Decided to turn off STRICTMODE and execute the same query:

orientdb {db=Customers}> alter class LeadYear STRICTMODE FALSE                    
Class updated successfully.

orientdb {db=Customers}> create edge LeadCreatedMonth from #218:0 to #229:2
Error: com.orientechnologies.orient.core.exception.OValidationException: Found additional field 'out_LeadCreatedMonth'. It cannot be added because the schema class 'LeadYear' is defined as STRICT
    DB name="Customers"
    DB name="Customers"

As you can see, console doesn't understand that the STRICTMODE is now off. I did schema reload again, but console didn't react to it either.

Executing the same query in the browser works, but only after StrictMode is false.

orientdb {db=Customers}> select from LeadYear                              

+----+------+--------+--------------------+------------------+--------------------+-----+-------+
|#   |@RID  |@CLASS  |in_LeadPurchasedYear|in_LeadCreatedYear|out_LeadCreatedMonth|value|account|
+----+------+--------+--------------------+------------------+--------------------+-----+-------+
|0   |#217:0|LeadYear|#253:0              |[]                |[#237:0,#237:1]     |2016 |#26:1  |
|1   |#218:0|LeadYear|                    |                  |[#240:0]            |2016 |#25:1  |
+----+------+--------+--------------------+------------------+--------------------+-----+-------+

Maybe I'm doing something wrong, but I can't figure out how to make it work in Strict Mode.

Thanks,

question

Most helpful comment

Hi guys,

Yes, I completely agree with your point of view, but unfortunately in v 2.2 the validation is performed at document level (in the core module, that does not know graph concepts) and the graph structure is managed on an upper layer (in the graph module), so it's nearly impossible to change this behavior.

In v 3.0 we are moving graph concepts to the core module, so probably we will be able to fix this

Thanks

Luigi

All 9 comments

Hi @borov333

When a class is in strict mode, OrientDB does not allow to create fields that are not explicitly in the schema.
When OrientDB tries to add an edge to your vertex, it also tries to create two properties, called out_LeadCreatedMonth (in the origin vertex) and in_LeadCreatedMonth (in the destination vertex), but it fails because of the strict mode.

What you have to do in this case is explicitly create this property in the schema, eg.

CREATE PROPERTY LeadYear.out_LeadCreatedMonth RIDBAG

I hope it helps

Thanks

Luigi

Sorry, it's

CREATE PROPERTY LeadYear.out_LeadCreatedMonth LINKBAG

not RIDBAG

Thanks

Luigi

Hey Luigi,

Wouldn't one think that if an edge class is added and linked between vertexes, that ODB could override the "Strict" setting of the Class in terms of edge properties? In other words, the properties to store edge links isn't really part of the fundamental schema of the class, but is rather an implementation detail of ODB's graph functionality. The one shouldn't have anything to do with the other really.

In fact, I'd go even a step further. If a class is considered an extension of V, then only ODB should alter the edge linking properties and nobody else.

Scott

Thanks Luigi for the explanation. I was not aware of this work around.

I do agree with Scott however, from the average user's point of view creating an edge seems more of simply connecting two classes. And the Strict Mode, appears as protecting the class structure. It feels more natural that I should be able to connect strict mode classes without a need for a work around.

Hi guys,

Yes, I completely agree with your point of view, but unfortunately in v 2.2 the validation is performed at document level (in the core module, that does not know graph concepts) and the graph structure is managed on an upper layer (in the graph module), so it's nearly impossible to change this behavior.

In v 3.0 we are moving graph concepts to the core module, so probably we will be able to fix this

Thanks

Luigi

As usual, there is almost always a logical explanation. :smile:

Luigi, sorry to hijack this issue a bit, but since you are so attentive here, could you have a look at my last post in the Google Group or in my PM to you on Gitter? Thanks!

Scott

Thanks for the explanation Luigi. Last question: when do you realistically see v3 will be available? We working on the project that is planned to go live in Jan-Feb, so I was hoping to move it to 3 before that to avoid the migration on live data.

Hi guys,

@smolinari checking it ;-)

@borov333 I'm afraid we will hardly release 3.0 before Feb... given current status, our goal is to release it in q1 or in April

Thanks

Luigi

@luigidellaquila - nevermind. I've found the answer myself. Sorry to bother you and go off topic here.

Scott

Was this page helpful?
0 / 5 - 0 ratings