2013-05-03 94 views
0

我使用Elastic Beanstalk實現了一個應用程序。由於某些類將被持久化,因此我使用(Apache的)JDO註釋與DataNucleus結合使用。在Elastic Beanstalk中使用JDO導致ClassNotPersistenceCapableException

在本地服務器上運行應用程序時,一切正常,這意味着我可以將普通的舊Java對象保存到連接的Amazon RDS。當部署相同的應用程序彈性青苗我收到以下錯誤信息:

org.datanucleus.api.jdo.exceptions.ClassNotPersistenceCapableException: The class "edu.kit.aifb.cloudcampus.dom.mgmt.Dozent" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found. 
NestedThrowables: 
org.datanucleus.exceptions.ClassNotPersistableException: The class "edu.kit.aifb.cloudcampus.dom.mgmt.Dozent" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found. 

org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:380) 
    org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:731) 
    org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:751) 

我想知道爲什麼發生這種情況,因爲我已經programmaticaly提高了我的教學班的代碼下面幾行

public void enhanceJDOClasses(String...clazzes) { 
    JDOHelper.getEnhancer().addClasses(clazzes).enhance(); 
} 

有任何推薦的方式來處理這個以另一種方式或任何人遇到類似的例外?任何幫助表示讚賞。

回答

0

所以該類的增強版本不在當前的classLoader中。該命令並沒有把它放在那裏,只是增強了類,並且一旦一個類(unnhanced)加載到ClassLoader中,它就不能被替換。但是,您可以將classLoader設置爲增強器

+0

啊,好的。所以你的意思是 'public void enhanceJDOClasses(String ... clazzes){ \t \t ClassLoader contextClassLoader = Thread.currentThread()。getContextClassLoader(); \t \t JDOHelper.getEnhancer(contextClassLoader).addClasses(clazzes).enhance(); \t}' 會解決這個問題嗎?我會試一試。謝謝你的答案。 – Bugra 2013-05-06 08:09:22

+0

這樣做。現在我還有其他例外。但是這解決了第一個問題。謝謝。 – Bugra 2013-05-06 09:11:45