1

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

eclideria
  • 141
  • 9
  • Bonjour, does you table ELEVE exist in the MySQL database ? – Greg Jeanmart Jun 21 '16 at 20:58
  • shouldn't be transaction-type="JTA" instead of transaction-type="RESOURCE_LOCAL"? – Leo Jun 21 '16 at 21:00
  • Hello, Yes it exist and the query "SELECT ID, ADRESSE, classe, date_naissance, NOM, PRENOM, SEXE FROM ELEVE" return what I expect in mysql console – eclideria Jun 21 '16 at 21:01
  • @leo Why should it be JTA ? – eclideria Jun 21 '16 at 21:05
  • because I suppose you want tomee to take care of the persistence -- see http://tomee.apache.org/jpa-concepts.html – Leo Jun 21 '16 at 21:07
  • At the end yes but for now I should be able to retrieve data with RESOURCE_LOCAL no ? By the way I just tryed to put: EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin(); and when i go on the url i get: Exception Description: Cannot use an EntityTransaction while using JTA. But my persistence.xml is still with RESOURCE_LOCAL. It seems that my persistence.xml is not the one that is taken in acount – eclideria Jun 21 '16 at 21:16
  • Could be a problem with case sensitivity, in both cases (jpa and manual test) you ran against the same database? – k5_ Jun 21 '16 at 21:56
  • @k5_ What do you mean exactly ? yes I'm using the same db for all my test – eclideria Jun 22 '16 at 05:14
  • @eclideria There are differences in the writing of tables and columns e.g. "ELEVE" -> "eleve" and "ID"->"id" that can cause this. But as the query works if you use it manually it should be fine. Anyway, it is better style to keep that consistent. – k5_ Jun 22 '16 at 12:20
  • Set logging to finest to see exactly what database is being accessed, and that your 'root' credentials are the same ones being used. My guess is the persistence unit you are accessing and using is NOT the one you've shown in the persistence.xml file, and is likely accessing a database different from the one you expect. You will have to search your project for other xml files to be able to change logging – Chris Jun 22 '16 at 14:36
  • @k5_ Yes I think you are right. – eclideria Jun 22 '16 at 20:11
  • @Chris I verified and this is the only one in my project. I edited my post and put the logs in. – eclideria Jun 22 '16 at 20:11
  • If you log in as DB user can you run the query? – Jonathan S. Fisher Jun 22 '16 at 20:29
  • @JonathanS.Fisher Do you mean using the app ? or using the mysql console ? By the way I have put the root user in persistence.xml so it should not be a probleme og right. But I will try with an other user... – eclideria Jun 22 '16 at 20:38
  • Via the mysql console. This looks like a simple mysql permissions error, not so much an eclipselink issue. – Jonathan S. Fisher Jun 22 '16 at 20:40
  • @JonathanS.Fisher Everything looks fine with another user. What looks strange is that I have the same error if I shutdown my mysql server. It seems that the mysql server is never reach... – eclideria Jun 22 '16 at 21:16

1 Answers1

4

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

This is the changes I had to do:

  • Remove the database related properties from the persistence.xml
  • Replace non-jta-data-source tag by jta-data-source in persistence.xml
  • Put the mysql connector jar in my server /lib
  • In my server /conf/tomee.xml I have added myDatasource configuration as a resource.
  • Put @XmlRootElement(name = "eleve") over my Eleve entity (this seems to be only mandatory on TomEE <7)

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"

eclideria
  • 141
  • 9