Digital Sanctum

software development, technology and other square topics

Google App Engine for Java: CRUD Operations with JDO and Spring MVC

with 3 comments

In a prior post, I provided and introduction to GAE for Java including getting your local development environment setup and uploading your application to Google’s servers.

For this post, I will outline how to do simple CRUD operations using GAE for Java and the latest version of Spring MVC (which is 3.0.0.M3). Combining GAE for Java and the Spring MVC framework makes for a powerful way of making your application both flexible and scalable.

Datastore Options with Google App Engine for Java

The basis for just about any web application generally includes a data store for storing information. Instead of a relational database like MySQL or Oracle, Google uses something called BigTable. For an explanation about how BigTable differs from a traditional relational database, you should check out “The Softer Side of Schemas” video from the Google I/O 2009 conference. With respect to GAE for java, you have essentially three different ways to interact with BigTable:

  1. JPA – Java Peristence API
  2. JDO – Java Data Objects
  3. Low level API – provided by Google for doing stuff that you can’t otherwise do with JPA or JDO. Note that both JPA and JDO use this low-level API under the covers.

Development with Google App Engine for Java

To make development with GAE for Java, the folks at Google provide a couple of different ways to compile, package, and deploy your application. For the two mainstream Java IDE’s, IntelliJ IDEA and Eclipse, there are plug-ins available. If you don’t have one of these IDE’s or prefer to work from the command line, there’s Ant scripts available. My IDE of choice is IntelliJ IDEA, and the plug-in available is actually actively developed by JetBrains, makers of IDEA.

Getting Started with the View

Below is a simple web form for collecting information on API’s:



Note the isELIgnored="false" attribute in the page directive. I found that this is essential when using JSTL expressions with GAE. Otherwise, you’ll get a nasty exception.

A Simple POJO with JDO Annotations

Spring 3 MVC Controller Using Annotations

Below is the class with an ApiService injected via Spring. It uses the nice REST url mappings with variable substitution introduced to the framework as of version 3:

Below is a custom class I introduced called GoogleDatastoreKeyEditor. This helps with being able to bind complex objects from a web form. Here I use some static methods KeyFactory.stringToKey(text) and KeyFactory.keyToString(value) to easily go back and forth between string and object representations of a Key.

Getting Interesting:

Here’s where all the actual work is done by providing methods that take care of the CRUD operations:

So that’s a whirlwind tour of how to do some simple CRUD options with GAE for Java and Spring MVC. I’m in the process of figuring out to do things like many-to-many relationships and indexes. Look for that in my next post.

Written by Shane

July 2nd, 2009 at 6:36 pm

3 Responses to 'Google App Engine for Java: CRUD Operations with JDO and Spring MVC'

Subscribe to comments with RSS or TrackBack to 'Google App Engine for Java: CRUD Operations with JDO and Spring MVC'.

  1. thanks for the hands-on,

    what’s with the code screenshots, though? why not go all the way and attach the code?


    6 Jul 09 at 3:34 pm

  2. Thanks for the post, I have subscribed to your blog.

    I thought that there were issues with using JPA and GAE because of BigTable (and not a relational database). Do you know if that is true or not? Your post suggests that one can use JPA with GAE.



    6 Jul 09 at 4:39 pm

  3. @Zvika At the time I did this post, screenshots were the fastest way to throw some syntax highlighted code up. I will post a download for the code in the future.

    @Matt There are “issues” with both JDO and JPA mostly surrounding the fact that GAE supports a subset of the APIs, not necessarily because it’s BigTable and not a relational database. You can get an overview of the Java APIs available to use with GAE here:


    6 Jul 09 at 5:04 pm

Leave a Reply