Cannot insert document if optional fields do not present

57 views
Skip to first unread message

Krisztian Kocsis

unread,
Sep 11, 2012, 6:29:26 AM9/11/12
to orient-...@googlegroups.com
Hi!

I have a schema-full class with some mandatory and many optional fields (property isMandatory() -> false).
If I try to insert a document that does not contain an optional field I got this exception:

Caused by: com.orientechnologies.orient.core.exception.OValidationException: The field 'placeOfBirth' cannot be null
        at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.validateField(ORecordSchemaAwareAbstract.java:174)
        at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.validate(ORecordSchemaAwareAbstract.java:66)
        at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1252)
        at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1242)
        at eu.optimaster.mai.database.DatabaseEngine.save(DatabaseEngine.java:665)

I really does not set setNullable(true) to this field but I'v set setMandatory(false)!

If I call setNullable(true) than it saves and when I reload it the document does not contain the field (which is the expected case).
But then if I set the field to 'null' than after save and reload the document will contain the field with 'null' value (which is also the expected case).

This is confusing because - in my oppinion - if a field is marked as NOT mandatory and the doc does not contain such fields that it should be saved without exceptions.

Krisztian Kocsis

unread,
Sep 11, 2012, 6:31:21 AM9/11/12
to orient-...@googlegroups.com
One more thing: this is also problem because it allows to specify the 'null' value but in my use case the field is missing or must have a proper value (nullable thins also adds space and speed overhead as in other RDBMs).

Krisztian Kocsis

unread,
Sep 11, 2012, 6:38:55 AM9/11/12
to orient-...@googlegroups.com
Environment: 1.2.0-SNAPSHOT 20120910, Win 7 64-bit, Java 7u7 64-bit

Luca Garulli

unread,
Sep 13, 2012, 3:30:02 AM9/13/12
to orient-...@googlegroups.com
Hi,
the piece of code responseable of that exception is contained in ORecordSchemaAwareAbstract.validateField():

...
 if (p.isNotNull() && fieldValue == null)
      // NULLITY
      throw new OValidationException("The field '" + p.getName() + "' cannot be null");
...

So seems that the property has notNull set. Can you check it by displaying the class information? Connect with the console and type:

orientdb> info class X

Where X is your class name.

Lvc@

--
 
 
 

Krisztian Kocsis

unread,
Sep 13, 2012, 4:27:30 AM9/13/12
to orient-...@googlegroups.com
Hi!

Yes, I mentioned that the filed was not set to allow 'null' values but it is confusing that the field is marked as
'not mandatory' (I didn't put that field to the ODocument) and when I try to save it than this excerption was thrown.

A missing field and a nulled field should be mean two different thing, what do you think?

The the expression should be modified to:

if (p.isMandatory() && p.isNotNull() && fieldValue == null)
...

If fields are represented as Maps internally than it should check the existence of the field with contains() not just using get() which returns 'null' for nulled fields and for missing fields but the two are not the same!

Luca Garulli

unread,
Sep 13, 2012, 4:53:24 AM9/13/12
to orient-...@googlegroups.com
Hi Krisztian,
the way notnull is supposed to work is exactly how you described it.

I've fixed this bug in SVN r6539.

Thanks,
Lvc@

--
 
 
 

Krisztian Kocsis

unread,
Sep 13, 2012, 5:07:34 AM9/13/12
to orient-...@googlegroups.com
Thanks Luca!
Reply all
Reply to author
Forward
0 new messages