How to use Request Factory with JPA Hibernate and PostgreSQL ?

473 views
Skip to first unread message

Manuel

unread,
Sep 25, 2012, 10:36:05 PM9/25/12
to google-we...@googlegroups.com
Hi everyone,

I want to use a postgres db with the RF JPA.
I dont know if I´m on the right way, but I thought i just have to edit the persistence.xml?


Thats what my persistence.xml look like:

<?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="jdbc.driver" value="org.postgresql.Driver" />
            <property name="jdbc.url" value="jdbc:postgresql://localhost:5432/dev_mash" />
            <property name="jdbc.user" value="postgres" />
            <property name="jdbc.password" value="q1" />
            <property name="show_sql">true</property>
            <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
            <property name="connection.pool_size" value="10" />
            <property name="current_session_context_class" value="thread" />
        </properties>
   
    </persistence-unit>
</persistence>


I just started to work on that, so any help is much appreciated.
If you need any further information, please let me know.

Thanks in advanced.

Regards

Jens

unread,
Sep 26, 2012, 4:09:32 AM9/26/12
to google-we...@googlegroups.com
If you want to use Hibernate I guess the persistence provider is wrong. Looks like its the one of EclipseLink.

-- J.

Manuel

unread,
Sep 26, 2012, 12:10:59 PM9/26/12
to google-we...@googlegroups.com
Hmm ok.. so whats the provider?
Found this org.hibernate.ejb.HibernatePersistence one.

I updated the provider and put my class (Worker.java) in the persistence.xml but Iam still get an exception:
When i create the EntityManagerFactory, ReflectiveServiceLayer.invoke(Method domainMethod, Object... args) throws an exception (InvocationTargetException).

So far, i couldnt find any tutorial to get this working.
So any help is much appreciated.

Regards


Thats my current persistence.xml:


<?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.hibernate.ejb.HibernatePersistence</provider>
        <class>de.mash.server.Worker</class>

   
        <properties>
            <property name="jdbc.driver" value="org.postgresql.Driver" />
            <property name="jdbc.url" value="jdbc:postgresql://localhost:5432/dev_mash" />
            <property name="jdbc.user" value="postgres" />
            <property name="jdbc.password" value="m4nu3l" />

            <property name="show_sql">true</property>
            <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
            <property name="connection.pool_size" value="10" />
            <property name="current_session_context_class" value="thread" />
        </properties>
   
    </persistence-unit>
</persistence>

Heres what i get from the console:

com.google.web.bindery.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:387)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1108)
    at com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport$1.onResponseReceived(DefaultRequestTransport.java:136)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Server Error: Explicit persistence provider error(s) occurred for "transactions-optional" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl, org.hibernate.ejb.HibernatePersistence from provider: org.hibernate.ejb.HibernatePersistence
    at com.google.web.bindery.requestfactory.shared.Receiver.onFailure(Receiver.java:44)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.onFail(AbstractRequest.java:118)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:359)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1108)
    at com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport$1.onResponseReceived(DefaultRequestTransport.java:136)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Unknown Source)

Manuel

unread,
Sep 26, 2012, 12:20:50 PM9/26/12
to google-we...@googlegroups.com
Some more Info:
Thats the Worker.java class:

package de.mash.project.server;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "Worker")
public class Worker {

    public static Worker findWorker(Long id) {
        // if (id == 0) {
        return null;
        // }
        // EntityManager em = entityManager();
        // try {
        // Worker worker = em.find(Worker.class, id);
        // return worker;
        // } finally {
        // em.close();
        // }
    }

    @Transient
    protected Object[] jdoDetachedState;

    // @Id
    // @GeneratedValue(generator = "auto_increment")
    // @GenericGenerator(name = "auto_increment", strategy = "increment")
    // @Column(name = "id")
    // private int id;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "salary")
    private int salary;

    public Worker() {
    }

    public Worker(String fname, String lname, int salary) {
        this.firstName = fname;
        this.lastName = lname;
        this.salary = salary;
    }

    public Long getId() {
        return id;
    }

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

    public String getFirstName() {
        return firstName;
    }

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

    public String getLastName() {
        return lastName;
    }

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

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public static Long countWorkers() {
        return 2l;
    }

    public Integer getVersion() {
        return 1;
    }

    public void persist() {
        // EntityManager em = entityManager();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("transactions-optional");
        EntityManager em = emf.createEntityManager();
        try {
            em.persist(this);
        } catch (Exception e) {
            int i = 1;
        } finally {
            em.close();
        }
    }

    public static final EntityManager entityManager() {
        return EMF.get().createEntityManager();
    }

}

Manuel

unread,
Sep 26, 2012, 1:16:04 PM9/26/12
to google-we...@googlegroups.com
Btw, do I have to disable App Engine ?   Actually My Project-Propertys->Google->App Engine-> Use Google App Engine is set.
Do I have to configurate jdoconfig.xml?

When i use the following persistence.xml I dont get the exception anymore, buts its still not working :(

Thats the output:
Sep 26, 2012 7:13:11 PM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000342: Could not obtain connection to query metadata : Der Verbindungsversuch schlug fehl.

Any ideas? :/
Adding i.e.  <property name="hibernate.connection.pool_size">10</property> I get the ecxeption again.

I had already tested the connection data with a jdbc connect, so they should be right.



Thats the xml:


<?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.hibernate.ejb.HibernatePersistence</provider>
<!--         <class>de.mash.server.Worker</class> -->
        <properties>
              <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
              <property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5432/dev_mash"/>
              <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
              <property name="hibernate.connection.username" value="postgres"/>
              <property name="hibernate.connection.password" value="m4nu3l"/>
            
        </properties>
   
    </persistence-unit>
</persistence>

Manuel

unread,
Sep 26, 2012, 7:43:33 PM9/26/12
to google-we...@googlegroups.com
Hey,

I use the following persistence.xml now. I dont get a exception anymore but I still dont get any records saved into my database either.

I also should see some SQL statements in my console if he would commit any SQL, right? I dont see any SQL :(

If I change databasename or password to any wrong value, I dont get any error/exception. Everything still "works".


Has anyone an idea? Any help is much appreciated.
Regards

Heres the persistence.xml:

<persistence-unit name="kunde" transaction-type="RESOURCE_LOCAL">
        <class>de.mash.project.server.Worker</class>
<!--         <jta-data-source>PostgresDS</jta-data-source>       -->

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.show_sql" value="true" />
           
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/dev_mash" />
            <property name="hibernate.connection.username" value="postgres" />
            <property name="hibernate.connection.password" value="m4nu3l" />
            <property name="hibernate.default_schema" value="public" />
           
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        </properties>
    </persistence-unit>

Manuel

unread,
Sep 28, 2012, 11:47:39 PM9/28/12
to google-we...@googlegroups.com
Hey,

here an update on my topic.

I could solve the problem.


I created a new Project without App Engine. Now the persistence.xml gets used like expected.
App Engine caused, that datanucleus instead of hibernate were used.

Regards
Reply all
Reply to author
Forward
0 new messages