My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
FrequentlyAskedQuestions  
Frequently Asked Questions
Featured
Updated May 3, 2012 by lhori...@gmail.com

Frequently Asked Questions

Why 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.

  1. Ignore the ObjectifyService class and its static methods. It is merely a static proxy for a single instance of ObjectifyFactory. Instead you will use ObjectifyFactory directly.
  2. Create an application-scoped ObjectifyFactory instance, register your classes, and inject it!
  3. Alternatively, use the DAO pattern (see BestPractices) and inject your DAO.

How do I shut off the datanucleus byte code enhancer?

  • In Eclipse, go to the Project Properties -> Builders and disable the 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...

  • You're still limited by GAE's restrictions on transactions (namely, all objects must be part of the same entity group).
  • If you have session caching enabled, the direct-datastore put() will bypass the session cache. If the session cache already held a value for that key, subsequent a get() from the Objectify instance will produce the (now incorrect) cached value.
  • The global cache will remain consistent as long as you obtain the DatastoreService from ofy.getDatastore(); if you get it directly from DatastoreServiceFactory it will bypass Objectify's global (memcache) cache.

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.

Comment by daniel.wilkerson@gmail.com, May 18, 2012

"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

Comment by project member lhori...@gmail.com, May 18, 2012

Projection queries are new, and yes this document needs to be updated to reflect that. GAE still isn't like SQL select/update though.


Sign in to add a comment
Powered by Google Project Hosting