Meetu Maltiar's Blog

Meetu's thoughts on technology and software development

Archive for September 27th, 2010

Google App Engine Some JPA Gotchas

leave a comment »


While porting an application to Google App Engine we encountered several issues. Most of them where related to persistence. We were using JPA for persistence in the application. One of the most common mistake we did was in issuing a JPA Query where one or more parameters are of type com.google.appengine.datastore.api.Key class. Key class has two String representations which lead to some confusion.

Let’s look at an example. There is a Department entity and its associated JpaDepartmentDAO data access object. This DAO has a method which returns a Department based on departmentKey which is of type com.google.appengine.datastore.api.Key.

@Entity
public class Department implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key departmentKey;
	
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Key getDepartmentKey() {
		return departmentKey;
	}

	public void setDepartmentKey(Key departmentKey) {
		this.departmentKey = departmentKey;
	}
}

Read the rest of this entry »

Written by Meetu Maltiar

September 27, 2010 at 22:57

Posted in Cloud, Java

Tagged with ,