Master Mind
Master Mind

Reputation: 2404

GAE : Google Cloud SQL + JPA is not working

When i connected my cloud sql instance with JPA using EclipseLink 2.2.1, it shows following error

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)

My code for persistance.xml is

<?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>

My Entity Manager Factory Class is :

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

    private EMF() {
    }

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

Servlet is :

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 Class is :

@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;
    }
}

Upvotes: 1

Views: 1309

Answers (1)

DataNucleus
DataNucleus

Reputation: 15577

One would think that if you want to use EclipseLink, then you would set the "provider" in "persistence.xml", since you have other JPA implementation(s) in the CLASSPATH too, or alternatively you fix the CLASSPATH to make sure there is only 1 JPA implementation present

Upvotes: 1

Related Questions