Hi Marc,
As the error message says, you should use a singleton to share your
persistence manager. Your code must be allocating it more than once. Here ya
go:
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.PersistenceManager;
final public class PMF {
private final static PersistenceManagerFactory pmf =
JDOHelper.getPersistenceManagerFactory("transactions-optional");
private PMF() {}
static public PersistenceManager getPersistenceManager() {
return pmf.getPersistenceManager();
}
}
Then to use it, just:
PersistenceManager pm = PMF.getPersistenceManager();
Stephen
On Mon, Jan 24, 2011 at 3:19 PM, Marc Herber <[email protected]>wrote:
> Meanwhile I tried this *java* code:
> PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(
> "transactions-optional" );
> PersistenceManager pm = pmf.getPersistenceManager();
> Antwort objectById = pm.getObjectById( Antwort.class, parameters.getLong(
> Constants.ID ) );
>
> And this is my *jdocnfig.xml*:
> <?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>
>
>
> But I get the subsequent exception:
> javax.jdo.JDOFatalUserException: Application code attempted to create a
> PersistenceManagerFactory named transactions-optional, but one with this
> name already exists! Instances of PersistenceManagerFactory are extremely
> slow to create and it is usually not necessary to create one with a given
> name more than once. Instead, create a singleton and share it throughout
> your code. If you really do need to create a duplicate
> PersistenceManagerFactory (such as for a unittest suite), set the
> appengine.orm.disable.duplicate.pmf.exception system property to avoid this
> error.
>
> Can anybody help me out?!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.