javamysqlweb-serviceseclipselinkapache-tomee

JavaEE + eclipseLink + TomEE gives java.sql.SQLSyntaxErrorException: user lacks privilege or object not found


I try to make a simple app using a rest service, eclipseLink and mysql. I want to make this run on a TomEE server (apache-tomee-plume-1.7.4).

I deploy the app with eclipse.

The deployment seems to be ok

When I go to http://localhost:8080/eleve/ I'm getting :

javax.servlet.ServletException: Error processing webservice request
    org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:98)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

java.io.IOException: Failed to invoke AbstractHTTPDestination
    org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:229)
    org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: 
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ELEVE
Error Code: -5501
Call: SELECT ID, ADRESSE, classe, date_naissance, NOM, PRENOM, SEXE FROM ELEVE
Query: ReadAllQuery(referenceClass=Eleve sql="SELECT ID, ADRESSE, classe, date_naissance, NOM, PRENOM, SEXE FROM ELEVE")
    org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
    org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:324)
    org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:240)
    org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:227)
    org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Here is my persistence.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.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_1_0.xsd">
    <persistence-unit name="notePU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.test.eleve.model.Eleve</class>
        <properties>
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/notes_eleves" />
            <!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
            <property name="eclipselink.logging.level" value="INFO" />
        </properties>
    </persistence-unit>
</persistence>

I must be missing something but I can not find what.

I pushed my code here: gitlab

Thanks for your help


Solution

  • I finally managed to make it works on TomEE 1.7 and 7.

    This is the changes I had to do:

    At the end I think that my issue was that the datasource needs to be configure in the server conf in a EE context (datasource properties in persistence was just ignore I think, so it was like no one was declared) and the exception

    user lacks privilege or object not found

    was comming from the fact that:

    If a DataSource is needed by the application and one is not declared, TomEE will create one dynamically using default settings.

    TomEE documentation

    I'm not 100% sure of that explanation but at least the problem is solved, don't hesitate to put comments if I misunderstood something.

    I have updated the gitlab project

    Edit: Be aware that you can also configure the resource in a /WEB-INF/resources.xml file

    Edit 2: If you are using Eclipse you can also face this issue if you wrongly configured your server location, it should be set to "use Tomcat installation (take control...)" and not "use workspace metadata"