Converting my GAE application from JDO to JPA

June 25, 2011 at 2:38 pm Leave a comment

In past I had used the GAE with JDO, and in this exercise I will convert it to JPA.

In javasource/META-INF is the jdoconfig.xml:

<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns=""
  <persistence-manager-factory name="transactions-optional">
    <property name="javax.jdo.PersistenceManagerFactoryClass" 
    <property name="javax.jdo.option.ConnectionURL" value="appengine"/>
    <property name="javax.jdo.option.NontransactionalRead" value="true"/>
    <property name="javax.jdo.option.NontransactionalWrite" value="true"/>
    <property name="javax.jdo.option.RetainValues" value="true"/>
    <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>

private static final PersistenceManagerFactory PMF =

Example write:

PersistenceManager pm = getPersistenceManager();
try {
  pm.makePersistent(new Movie(getUser(), symbol, note));
} finally {

Example read and delete:

Query q = pm.newQuery(Movie.class, "user == u");
q.declareParameters(" u");
List<Movie> movies = (List<Movie>) q.execute(getUser());
for (Movie movie : movies) {
if (moviename.equals(movie.getSymbol())) {

Now to JPA queries:


private static final EntityManagerFactory EMF =
private EntityManager getEntityManager() {
	    return EMF.createEntityManager();
EntityManager em = getEntityManager();
		// Read the existing entries
		javax.persistence.Query q = em.createQuery("select m from Movie m");

public class Movie {

  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

Entry filed under: Uncategorized.

Places and Activity – advancing MVP model Developer Sharing June Edition

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: