@Parent nullable in v2.2.2: could it be optional ?

50 views
Skip to first unread message

Didier DURAND

unread,
Nov 5, 2010, 2:56:13 AM11/5/10
to objectify-appengine
Hi,

v2.2.2 now supports nullable @Parent fields: when you store a child
entity without having its parent set, it now goes through without
complaining (used to throw an exception)

My question: would be it possible to choose the behavior of Objectify
with null parents (like @Parent("nullable") to be able to enforce the
old 2.2.1 behavior or the new one.

It's important to make sure that parent is properly set in some cases:
it avoids spreading children in other entity groups and then having an
atomicity issue in a subsequent transaction where you need to update
simultaneously the parent and the child.

Of course, @PrePersist method can be used to make this check but it
would save code if the option was possible at annotation level.

I would suggest the default (i.e @Parent with no ("") option) to be
the original one of 2.2.1: it has to be a voluntarily expressed
behavior to relax this constraint from my point of view. Additionally,
it will help people migrating from 2.2.1 and before to keep a
consistent behavior across versions.

regards

didier

Jeff Schnitzer

unread,
Nov 5, 2010, 2:08:52 PM11/5/10
to objectify...@googlegroups.com
This is exactly the sort of thing that Emmanuel's JSR303 bean
validation code is for. I would certainly love to see an Objectify
extension that uses the Hibernate Validator (and I might even get
around to writing it myself one of these days), but I'm opposed to
adding a nonstandard, overlapping set of annotations.

The JSR303 version would look like this:

class MyThing {
@Id Long id;

@NotNull
@Parent Key<ParentThing> parent;

...

Didier DURAND

unread,
Nov 6, 2010, 4:03:16 AM11/6/10
to objectify-appengine
Hi Jeff,

I did not know about this JSR303 for validation: @NotNull is also fine
for me.

I agree with your willingness to stick to standards.

Hope this @NotNull comes soon!
regards
didier
Reply all
Reply to author
Forward
0 new messages