|
FrequentlyAskedQuestions
Frequently Asked Questions
Featured
Frequently Asked QuestionsWhy am I getting NoSuchMethodError exceptions on GAE classes?You probably are running an old version of the Google App Engine SDK; check the Objectify ReleaseNotes to see what minimum version is required. Google is rapidly developing Appengine; as they add new features, we add support to Objectify. This tends to require up-to-date versions of the SDK. Can I use Dependency Injection (Spring, Guice, Weld) with Objectify?Yes! Objectify was designed with this in mind.
How do I shut off the datanucleus byte code enhancer?
Can I change data after it is loaded or before it is stored?Absolutely:
Should I Use a String (Name) Id?If it is a natural key, sure; Objectify allows this no problem. Here is a little more of a discussion about it. How can I integrate with memcached?See the Caching documentation. Hint, add @Cached to your (entity) class. How do I do a like query (LIKE "foo%")You can do something like a startWith, or endWith if you reverse the order when stored and searched. You do a range query with the starting value you want, and a value just above the one you want. String start = "foo";
... = ofy.query(MyEntity.class).filter("field >=", start).filter("field <", start + "\uFFFD"); See this discussion for more background and details How do I migrate from JDO to Objectify?You should have no trouble using Objectify side-by-side with JDO. Just don't use the javax.persistence.Entity annotation on Objectify entities, it will likely make the JDO bytecode enhancer try to enhance it. You can either leave the annotation absent or use the com.googlecode.objectify.annotation.Entity substitute annotation instead. For the most part, migrating JDO classes to Objectify classes should be pretty straightforward. The only trick will be mapping the relationships. Look at the raw Entity objects to see what structure JDO created - relationships are just a Key on one end or both. If you make this field a Key<?> (or Collection<Key<?>>) in your Objectify entities, it will map just fine. Does Objectify support JDO Fetch Groups?There is no such thing as a fetch group in the GAE datastore; entities are fetched in their entirety or not at all. Objectify reflects the underlying nature of the datastore so it does not require this JDO-ism. Does Objectify support JDO detach copy?There is no need for this JDO-ism either. Objectify entities are exactly as you define them. They are not bytecode-enhanced, proxied, or manipulated in any way. Want to serialize your entity? Just make sure it is Serializable. Can I mix Low Level and Objectify writes in a single Objectify transaction?Example... Objectify ofy = ObjectifyService.beginTransaction(); ofy.put(makeSomeObject()); ofy.getDatastore().put(makeSomeLowLevelEntity()); ofy.getTxn().commit(); Yes you can! With a few caveats...
But yeah, you're free to interleave Objectify and Low-Level API calls. Why can't I use @Embedded on List<String>?@Embedded tells Objectify to break classes down to their component parts based on their fields and store each field separately. Therefore, this annotation must not be used on primitive types or types that are stored natively by the datastore (eg String, Integer, GeoPt, User, Email, etc). The datastore knows how to persist these native types as-is. You do not need the @Embedded annotation to persist a List<String> - just declare the field normally. | |
"entities are fetched in their entirety or not at all"
What about Projection Queries?: https://developers.google.com/appengine/docs/java/datastore/queries#Query_Projection
Projection queries are new, and yes this document needs to be updated to reflect that. GAE still isn't like SQL select/update though.