My domain model is getting real now and I’ve had to use AppEngine’s Key class in one of my domain objects to model a one-to-many relationship:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true") public class PrayerList implements Serializable { ... @Persistent private Key listOwner; ... }
As has been discussed in several forums, GWT does not emulate any AppEngine classes, so there are a few possible workarounds:
- Create a DTO that does not contain any AppEngine classes for each domain object. DTOs, yuck.
- Provide an emulated Key class yourself following Fred Sauer’s fine instructions.
- Use the GILEAD project’s Adapter4AppEngine, which supplies GWT with emulated classes for AppEngine’s Key, Text, Blob, and other troublesome types.
Without Adapter4AppEngine:
Removing units with errors [ERROR] Errors in 'file:/C:/Users/David/workspace/ROA/src/com/roa/client/domain/PrayerList.java' [ERROR] Line 12: The import com.google.appengine cannot be resolved [ERROR] Line 30: Key cannot be resolved to a type
With Adapter4AppEngine:
Compiling 6 permutations Permutation compile succeeded
According to the GILEAD project’s home page,
Gilead stands for Generic Light Entity Adapter
It permits you to send Persistent entities (and especially the partially loaded ones) outside the JVM (GWT, Flex, Web-Services, Google AppEngine …) without pain.
Adapter4AppEngine is simple to use. Just drop in the jar and add the required <inherits> tag in your gwt.xml.
Nice!