Abstract Base Entity Class?

237 views
Skip to first unread message

Rick Mangi

unread,
Mar 18, 2012, 9:34:24 PM3/18/12
to objectify...@googlegroups.com
Hey,

Is there any way to have an object hierarchy in Objectify 4 with an abstract class as the root of the hierarchy? I tried it and got an exception because the root class couldn't be instantiated..

Jeff Schnitzer

unread,
Mar 18, 2012, 11:14:46 PM3/18/12
to objectify...@googlegroups.com
I keep bumping into this myself. Yes, it will be fixed, but there
will be a minor consequence.

Right now Objectify4 has @Entity and @EntitySubclass annotations. If
you have a polymorphic entity, the root has the same annotation as a
non-polymorphic hierarchy. Unfortunately Objectify really needs to be
able to distinguish between these two cases... so @Entity will
probably be split into @Entity and @EntityBase. This would allow
@EntityBase to be abstract while @Entity cannot be... but more
importantly, it allows us to distinguish when you put conditional
@Load statements on polymorphic entities and throw an immediate error
message at registration time.

Jeff

Ronoaldo José de Lana Pereira

unread,
Mar 19, 2012, 4:44:23 PM3/19/12
to objectify...@googlegroups.com
Does this is needed to implement the Active Record pattern with Objecitfy? Not sure if this is a good pattern or not, but makes code savings + a nice API in some use cases...

Jeff Schnitzer

unread,
Mar 19, 2012, 10:19:33 PM3/19/12
to objectify...@googlegroups.com
I'm sorry... I don't quite understand what you are asking :-(

Jeff

2012/3/19 Ronoaldo José de Lana Pereira <rper...@beneficiofacil.com.br>:

Rick Mangi

unread,
Mar 20, 2012, 10:34:39 AM3/20/12
to objectify...@googlegroups.com
My understanding of the Active Record pattern would not require an abstract base class, but it's also not really a good pattern for working with Objectify. In my opinion, you're better off using DAO classes to wrap basic CRUD operations and finders for common use-cases. Keep it simple :)

That said, I don't see any reason why you couldn't use active records, unless you were going to put all of the data access logic in a base class and then inherit from this for each of your entity objects. We do it the other way, an abstract DAO class that wraps basic CRUD using generics and then a concrete dao for each entity that handles registering the entities and implements more fine grained finder methods. It's a breath of fresh air after using JDO with GAE.




On Monday, March 19, 2012 10:19:33 PM UTC-4, Jeff Schnitzer wrote:
I'm sorry... I don't quite understand what you are asking :-(

Jeff

2012/3/19 Ronoaldo José de Lana Pereira:

Ronoaldo José de Lana Pereira

unread,
Mar 20, 2012, 11:13:09 AM3/20/12
to objectify...@googlegroups.com
Thanks for your tips, I was doing all the way wrong! You are right, no need to implement the ActiveRecord pattern using inheritance, and this is even a good design practice.

Jeff, sorry, I wasn't clear enough, but Rick got the point.

Best Regards,

-Ronoaldo

Rick Mangi

unread,
Mar 20, 2012, 11:14:24 AM3/20/12
to objectify...@googlegroups.com
Nice. Glad to be of help.
Reply all
Reply to author
Forward
0 new messages