问题描述
我尝试使用REST服务,eclipseLink和mysql创建一个简单的应用程序。
我想在TomEE服务器(apache-tomee-plume-1.7.4)上运行它。
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).
我使用eclipse部署应用程序。
I deploy the app with eclipse.
部署似乎还可以
当我进入我正在获取:
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)
这是我的persistence.xml:
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
感谢您的帮助
推荐答案
我终于设法使其适用于TomEE 1.7和7。
I finally managed to make it works on TomEE 1.7 and 7.
这是我要做的更改:
- 从以下位置删除与数据库相关的属性persistence.xml
- 在persistence.xml中通过jta-data-source替换非jta-data-source标签
- 将mysql连接器jar放入我的服务器/ lib
- 在我的服务器/conf/tomee.xml中,我已将myDatasource配置添加为资源。
- 放入@XmlRootElement(name =我的Eleve实体上的删除)(这似乎仅在TomEE
- 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)
最后,我认为我的问题是,数据源需要在EE上下文中的服务器conf中进行配置(数据持久性中的源属性只是我想忽略的,所以就好像没有人声明过),并且例外
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
来自以下事实:
我不是100%肯定该解释,但至少问题已解决,如果我误解了某些内容,请不要犹豫发表评论。
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.
我已经更新了
编辑:请注意,您也可以在/WEB-INF/resources.xml文件中配置资源
Be aware that you can also configure the resource in a /WEB-INF/resources.xml file
编辑2:如果您使用的是Eclipse,并且您错误地配置了服务器位置,则也可能会遇到此问题,应将其设置为使用Tomcat安装(控制...)而不是使用工作空间元数据
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"
这篇关于JavaEE + eclipseLink + TomEE提供了java.sql.SQLSyntaxErrorException:用户缺少特权或找不到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!