UpgradeVersion6ToVersion61 - objectify/objectify GitHub Wiki

Upgrading Objectify v6 to v6.1

The good news is that there are no major breaking API changes in this release. However, several significant methods have been deprecated and will be removed in the next major version of Objectify.

In versions of Objectify prior to 6.1, the ObjectifyService class (and the singleton ObjectifyFactory it contains) was special. You had to initialize the singleton, and certain methods (like some of the Key.create() overloads) relied on the singleton. This didn't make it impossible to use multiple ObjectifyFactorys (multiple datastores) in a single application, but it made it difficult.

Objectify 6.1 eliminates inbound references to the ObjectifyService class, rendering it optional. ObjectifyService is still the easiest way to use Objectify and the Objectify documentation will continue to use its static methods. But as of v6.1, ObjectifyService nothing more than a container for an ObjectifyFactory.

The consequences:

Most Key.create() methods are deprecated

Datastore Keys contain the datastore id. Consequently, to create an Objectify Key<?> from a type and id, we need a reference to the datastore. These methods reference the ObjectifyService singleton factory and therefore have been deprecated:

  • Key.create(Class<?> kindClass, long id)
  • Key.create(Class<?> kindClass, String name)
  • Key.create(Key<?> parent, Class<?> kindClass, long id)
  • Key.create(Key<?> parent, Class<?> kindClass, String name)
  • Key.create(String namespace, Class<?> kindClass, long id)
  • Key.create(String namespace, Class<?> kindClass, String name)
  • Key.create(Object pojo)

What to call instead? First, if you are using ObjectifyService, you can call equivalent static methods on ObjectifyService:

import static com.googlecode.objectify.ObjectifyService.key;

Key<Thing1> key1 = key(Thing1.class, 123L);
Key<Thing2> key2 = key(Thing2.class, "identifier");
etc...

Alternatively, you can call the same key() methods on an ObjectifyFactory instance:

ObjectifyFactory factory = // get the factory somehow
Key<Thing1> key1 = factory.key(Thing1.class, 123L);
Key<Thing2> key2 = factory.key(Thing2.class, "identifier");
etc...

Note that two Key.create() methods remain, and will not be deprecated:

  • Key.create(com.google.cloud.datastore.Key raw)
  • Key.create(String urlSafeString)

Since an Objectify Key<?> simply wraps a low-level datastore SDK Key, these operations do not require a datastore/ObjectifyFactory reference.

Most Ref.create() methods are deprecated

Ref<?> has the same problem as Key<?> above. Create Ref<?>s using the ref() methods on ObjectifyService and/or ObjectifyFactory.

Ref<?> is no longer serializable

This is technically a breaking change, but it should be obscure enough that nobody is affected. If that's not true, reach out.

Ref<?>'s special ability is to load its value. This requires a reference to the appropriate ObjectifyFactory, and we can no longer assume ObjectifyService.factory() is relevant. So Ref<?> now contains a direct reference to its (not at all serializable) factory.

⚠️ **GitHub.com Fallback** ⚠️