gpt4 book ai didi

google-app-engine - 使对象持久化时出错

转载 作者:太空宇宙 更新时间:2023-11-03 15:32:30 25 4
gpt4 key购买 nike

我正在尝试使用 JDO 在 GAE 平台上编写 Vaadin 应用程序,当我想调用此方法时:

public void createUser(String login, String password, String email) {
PersistenceManager pm = PMF.get().getPersistenceManager();
User user = new User(login, password, email);
try {
pm.makePersistent(user);
} finally {
pm.close();
}

}

我收到这个错误:

(...)Caused by: javax.jdo.JDOFatalUserException: A property named javax.jdo.PersistenceManagerFactoryClass must be specified, or a jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath, or a property named javax.jdo.option.PersistenceUnitName must be specified. NestedThrowables: javax.jdo.JDOUserException: You have either specified for this PMF to use a "persistence-unit" of "transactions-optional" (yet this doesnt exist!) or you called JDOHelper.getPersistenceManagerFactory with "transactions-optional" as the name of a properties file (and this doesnt exist in the CLASSPATH) at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:856) at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1092) at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:914) at myapp.PMF.(PMF.java:8) ... 43 more Caused by: javax.jdo.JDOUserException: You have either specified for this PMF to use a "persistence-unit" of "transactions-optional" (yet this doesnt exist!) or you called JDOHelper.getPersistenceManagerFactory with "transactions-optional" as the name of a properties file (and this doesnt exist in the CLASSPATH) (...)

我已经在 Google 上进行了搜索并找到了解决此问题的一些解决方案,但没有一个适用于我的应用程序(或者我做错了什么)。例如。 this不会工作。哦,我在 META-INF 中有 jdoconfig.xml 文件。如果有人有类似的问题,并且他愿意分享他的智慧,我将不胜感激。

编辑:jdoconfig 文件:

<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory" />
<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" />
</persistence-manager-factory>
</jdoconfig>

最佳答案

明白了!

jdoconfig.xml

文件在

\war\META-INF

Eclipse 创建的目录。应该在

\war\WEB-INF\classes\META-INF

愚蠢的错误...

关于google-app-engine - 使对象持久化时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10350621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com