Amir Peivandi
Amir Peivandi

Reputation: 369

Issue with GAE, JPA and Hibernate setup

All, I'm trying to configure Google App Engine to work with my local MySQL database instance and JPA using Hibernate. After setup I had a socket issue that I realized is discussed before (http://stackoverflow.com/questions/10585140/gae-cloudsql-with-mysql-access-denied) so I followed the instructions and tried to resolve my issue. however for some reason eclipse is doing something annoying and wipes out my changes made to persistence.xml file as it's instructed in the mentioned post.

To test this I installed a fresh Eclipse (Juno) and loaded the google plugin. I create a test application I add JPA to is and set it up to use hibernate. I google app property I make sure it's using local mysql

So far so good. When I look at the generated persistence.xml I see this:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd" version="1.0">
    <persistence-unit name="transactions-optional" transaction-type="RESOURCE_LOCAL">
    <provider></provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/shelem?user=root&amp;password=gandom"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="gandom"/>
        </properties>
    </persistence-unit>
</persistence>

As you can see the provider is set to nothing (wrong) and URL and Driver attributes are also wrong (as per mentioned post). If I run the application as is I'll get the socket error exception mentioned in the above post so I manually change the persistence.xml file to look like this (as per above post):

<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd" version="1.0">
    <persistence-unit name="transactions-optional" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
            <property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://localhost/Guardian"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="gandom"/>
        </properties>
    </persistence-unit>
</persistence>

Then the crazy thing happens! As soon as I do this and I clean/build the application so I can start it Eclipse wipes out my changes and turn the persistence.xml file to look like what it was before my manually made changes and ..... Interestingly if I add comments or change anything else those changes are kept and are not lost so it seems for some reason eclipse only replaces the code that was suggested to fix my issues!!!

It's been driving me crazy, anyone has seen this? Any suggestions?

Thanks for your comments.

Amir

Upvotes: 0

Views: 459

Answers (1)

Amir Peivandi
Amir Peivandi

Reputation: 369

It seems at least with version 1.7 of the app engine you can not use anything but EclipseLink as the persistence provider. Using EL is not a major concern as regardless of what is used to access your local database Google uses its own provider on the app engine server farms.

That said it's maybe even for the best to use EclipseLink for local development as well since any persistence provider specific logic you may embed in your code that is not compatible with google's provider would eventually come back and break your code after deployment so safer approach is to use EclipesLink on local.

Hope this helps others so they don't waste time as I did.

Upvotes: 1

Related Questions