`

迁移到appengine平台上

阅读更多

appengine是google的云计算平台,目前支持java, python语言开发网站等程序。我准备把最近开发的一个web迁移到appengine上面。这里记录所碰到的问题。

 

系统采用JPA + spring annotation transaction  + spring annotation MVC作为框架。

 

1。 enitity id

以前采用Integer作为enitity id,现在迁移appengine需要使用Long类型。

从跨平台的角度考虑,gae要求对象必须属于一个对象组,这样子对象使用String作为id。如果使用Hibernte +mysql平台的时候,必须使用uuid方式生成主健。可以参见如下的文章:http://xiaogui9317170.iteye.com/blog/283526

 

2。 JPQL query string

由于以前使用 hibernate + JPA,因此查询语句使用HQL是没有问题的。比如 'from User u'; 但是appengine使用标准的JPA, 应当修改为'select u from User u'。

 

3。eager loading 不支持

Child objects are loaded from the datastore when they are accessed for the first time. If you do not access the child object on a parent object, the entity for the child object is never loaded. (The datastore interface does not support the "eager" loading of child objects. The datastore does not support join queries, so an implementation of eager loading wouldn't save the app a call to the datastore.)

 

4。关联关系

A relationship between persistent objects can be described as owned, where one of the objects cannot exist without the other, or unowned, where both objects can exist independently of their relationship with one another.

The child class must have a key field whose type can contain the parent key information: either a Key, or a Key value encoded as a string.

App Engine does not support join queries: you cannot query a parent entity using an attribute of a child entity. (You can query a property of an embedded class, because embedded classes store properties on the parent entity

 

5。Spring框架

通过实验发现,spring2.5由于依赖了Javax.naming包而无法在GAE环境中运行正常。参考了GAE issue1240里面的方法,系统终于能正常运行,但是entityManager无法通过spring的@PersistContext设置成功。最后全部采用spring3后系统终于能正常运行。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics