當前使用的GAE版本為1.2.1 for java
1. 使用Eclipse時出現編譯警告(XXX has annotations but there is no registered AnnotationReader. Please check your CLASSPATH and the annotations in the class for validity. )
解決辦法:修改ORM Enhancement(http://code.google.com/eclipse/docs/appengine_orm.html)
參考鏈接: http://groups.google.com/group/google-appengine-java/browse_thread/thread/90850aad49730245
2.
發送郵件時發生com.google.apphosting.api.ApiProxy$CallNotFoundException
解決辦法:單純的運行郵件發送程序是不行的,需要發布后再執行。如果需要單元測試,需要配置setUp與tearDown
1 @BeforeTest
2 public void setUp() throws Exception {
3 ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment());
4 ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")) {});
5 }
6 @AfterTest
7 public void tearDown() throws Exception {
8 // not strictly necessary to null these out but there's no harm either
9 ApiProxy.setDelegate(null);
10 ApiProxy.setEnvironmentForCurrentThread(null);
11 }
參考鏈接:http://groups.google.com/group/google-appengine-java/browse_thread/thread/debc5bcb69a6871f
3. 前臺處理要顯示數據時發生org.datanucleus.exceptions.NucleusUserException
解決辦法:在PersistenceManager.close()前,使用PersistenceManager.detachCopy(DATA)返回數據
4. 使用SpringMVC發生
java.lang.NoClassDefFoundError: javax/naming/NamingException
解決辦法:不要使用spring all-in-one.jar,使用需要的各個模塊jar
參考鏈接:http://groups.google.com/group/google-appengine-java/browse_thread/thread/f1a541fe52e172dd
5. one-to-many情況下使用Collection.add()發生java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
解決辦法:one的
主鍵不要使用Long,使用String或Key等。
參考鏈接:http://groups.google.com/group/google-appengine-java/browse_thread/thread/10e6cede7fb678f3/62d9505da8ec43bd
6. 不能插入one-to-many中的many方數據
解決辦法:JDO這點做的讓人比較不適應,需要手動維護one方的關系才行,具體步驟為:
a)檢索出one
b)維護many對象的one關系
c)維護one對象的many配列關系(重要)
d)保存
e)保證以上操作在一個事務中進行
示例代碼:
1 Child c = new Child();
2 PersistenceManager manager = JdoUtil.getPMF().getPersistenceManager();
3 Parent p = manager.getObjectById(Parent.class, Parent.getId());
4 c.setParent(p);
5 p.getChildren().add(c); // important
6 manager.makePersistent(c);
7 manager.close();
GAE for java 還處在發展階段,像JDO/JPA、File upload、image api等的處理還有不少需要完善的地方。
由上面的第6點可以看出,事務處理是一個比較棘手的課題。我的下個目標就是要好好設計它,也許OSIV是個不錯的選擇:-)