1

EclipseLink 2.2.1を使用してクラウドSQLインスタンスをJPAに接続すると、次のエラーが表示されます

W 2012-10-24 12:21:46.120
org.datanucleus.metadata.xml.AbstractMetaDataHandler error: MetaData Parser encountered an error in file "file:/base/data/home/apps/s~appengineaplicationID/8.362672796318745816/WEB-INF/classes/META-INF/persistence.xml" at line 2, column 248 : cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'persistence' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'. - Please check your specification of DTD and the validity of the MetaData XML that you have specified.

W 2012-10-24 12:21:46.885
Error for /jpatest
java.lang.ExceptionInInitializerError
    at com.my.jpa.ContactService.createContact(ContactService.java:20)
    at com.my.jpa.JPATestServlet.doGet(JPATestServlet.java:16)
Caused by: org.datanucleus.exceptions.NucleusUserException: No available StoreManager found for the datastore URL key "". Please make sure you have all relevant plugins in the CLASSPATH (e.g datanucleus-rdbms?, datanucleus-db4o?), and consider setting the persistence property "datanucleus.storeManagerType" to the type of store you are using e.g rdbms, db4o

W 2012-10-24 12:21:46.887
Nested in java.lang.ExceptionInInitializerError:
javax.persistence.PersistenceException: Provider error. Provider: org.datanucleus.jpa.PersistenceProviderImpl
    at javax.persistence.Persistence.createFactory(Persistence.java:176)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:112)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:66)
    at com.my.jpa.EMF.<clinit>(EMF.java:8)
    at com.my.jpa.ContactService.createContact(ContactService.java:20)
    at com.my.jpa.JPATestServlet.doGet(JPATestServlet.java:16)

C 2012-10-24 12:21:46.893
Uncaught exception from servlet
java.lang.ExceptionInInitializerError
    at com.my.jpa.ContactService.createContact(ContactService.java:20)
    at com.my.jpa.JPATestServlet.doGet(JPATestServlet.java:16)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

私のpersistance.xmlのコードは

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="JPATest">
        <class>com.my.jpa.Contact</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.google.cloud.sql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://instance_name/db" />
            <property name="javax.persistence.jdbc.user" value="" />
            <property name="javax.persistence.jdbc.password" value="" />
        </properties>
    </persistence-unit>
</persistence>

私のエンティティマネージャファクトリクラスは次のとおりです。

public final class EMF {
    private static final EntityManagerFactory emfInstance = Persistence
            .createEntityManagerFactory("JPATest");

    private EMF() {
    }

    public static EntityManagerFactory get() {
        return emfInstance;
    }
}

サーブレットは:

public class JPATestServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {        
        ContactService service = new ContactService();
        service.createContact(new Contact("Manu", "Mohan", "686019", "TVM"));
        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, world");
    }
}

エンティティクラスは:

@Entity
public class Contact {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String firstName;
    private String lastName;
    private String phoneNumber;
    private String address;

    public Contact() {
    }

    public Contact(String fn, String ln, String pn, String addr) {
        this.firstName = fn;
        this.lastName = ln;
        this.phoneNumber = pn;
        this.address = addr;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
4

1 に答える 1

1

EclipseLink を使用する場合は、「persistence.xml」に「provider」を設定します。これは、CLASSPATH にも他の JPA 実装があるためです。または、CLASSPATH を修正して、そこにあることを確認してください。 1 つの JPA 実装のみが存在する

于 2012-10-24T07:12:04.517 に答える