Hi, I am developing an application that requires persisting of different object categories that are all subclasses of a specific type. Say I have a super class Vehicle and two subclasses Car extends Vehicle and Ship extends Vehicle. Ideally what I would like to do is to be able to query across all Vehicle objects as well as Car and Ship objects separately.
It looks like the PolyModel class from the app engine Python API does this ( http://code.google.com/appengine/docs/python/datastore/polymodelclass.html or http://code.google.com/appengine/articles/polymodel.html) However, from the following thread it seems like this is not (yet?) supported in the Java API: http://groups.google.com/group/google-appengine-java/browse_thread/thread/99f9b92322ccf862/7b4a53d780a033cf?lnk=gst&q=PolyModel+java#7b4a53d780a033cf To get around this *limitation* I do something like this class Vehicle { String id; ............ ............ *String vehicleType;* // indicates what the vehicle type is, eg: Car / Ship. *Text vehicleData;* // a blob of text that is a String representation of a JSONObject that contains info specific to a vehicle type. } I am aware that one immediate flaw in my approach is that you cannot query by vehicleType specific fields contained in the vehicleData blob. This is * *NOT** important for my current app (I only need to query across vehicle properties but the view on the client side depends on the vehicleType). However, I am interested in knowing if it is possible to get around this? The front end for my app uses GWT and basically what it does is it gets Vehicle objects via RPC and triggers the corresponding presenter & view based on the vehicleType. Each presenter in turn knows what to do with the corresponding vehicleData JSON blob. I am really not sure if this is a good approach and am wondering if there are any best practices when it comes to persisting polymorphic class hierarchies. Am currently using Objectify (http://code.google.com/p/objectify-appengine/) for persistence but there doesn't seem to be any built-in support for polymorphism as yet. Thanks, Krishna -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
