简体   繁体   中英

i have this exception when execution of Entity Manager Factory creation statement

when execute this java code,that make select from datastore ,an exception was appeared due to first row,so how i can solve this exception? exception:

javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "transactions-optional" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl from provider: org.datanucleus.api.jpa.PersistenceProviderImpl

code:

PrintWriter out = resp.getWriter();
try {
    EntityManagerFactory emfactory = Persistence
            .createEntityManagerFactory("transactions-optional");
    EntityManager entitymanager = emfactory.createEntityManager();
    javax.persistence.Query query = entitymanager.createQuery("Select u from test u");
    List<test> list = (List<test>) query.getResultList();
    out.print(list.size());
} catch (Exception e) {
    out.println(e.toString());
} finally {
    out.close();
}

persistence.xml:

  <persistence-unit name="transactions-optional"> <provider> org.datanucleus.store.appengine.jpa.DatastorePersistenceProviderImpl </provider> <properties> <property name="datanucleus.NontransactionalRead" value="true" /> <property name="datanucleus.NontransactionalWrite" value="true" /> <property name="datanucleus.ConnectionURL" value="appengine" /> </properties> </persistence-unit> </persistence> 

As the Exception that you posted in the Comments (!) says

org.datanucleus.metadata.InvalidClassMetaDataException: Class s.follows has application-identity and no objectid-class specified yet has 0 primary key fields. Unable to use SingleFieldIdentity. 

Yet you don't post this class (why?! don't you think people may want to see it, when it is what the exception is about?).

Solution : mark a field as @Id just like all JPA docs say to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM