为什么我在 servlet 中收到无效模式错误,而在 main 函数中却没有相同的代码?
Why I get an invalid schema error in a servlet, with same code in main function not?
我和一些学生有一个项目。
一个 RefugeeWelcome 网站:
- TomEE 1.7.3(Plume 版本)
- MariaDB:服务器版本:10.1.10-MariaDB-1~jessie-log mariadb.org 二进制分发
- IDE:IntelliJ IDEA 15.0.2
- JRE: 1.8.0_51
要从数据库中获取数据,我正在使用 Criteria API / JPA。
这里是工作的主要功能:
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("RefugEEWelcomeApp");
EntityManager em = emf.createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<TblProductCategoryEntity> query = builder.createQuery(TblProductCategoryEntity.class);
Root<TblProductCategoryEntity> productCategoryEntityRoot = query.from(TblProductCategoryEntity.class);
Predicate mainCatNull = builder.isNull(productCategoryEntityRoot.get(TblProductCategoryEntity_.maincategory));
query.select(productCategoryEntityRoot).where(mainCatNull);
List<TblProductCategoryEntity> results = em.createQuery(query).getResultList();
for(Object o:results)
{
TblProductCategoryEntity e=(TblProductCategoryEntity) o;
System.out.println(
"ID : "+e.getIdtblProductCategory()
+"\tAtt: "+e.getAttachments()
+"\tCAT: "+e.getMaincategory());
}
}
控制台输出:
[EL Info]: 2015-12-29 19:26:22.731--ServerSession(1275240546)--EclipseLink, version: Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3
[EL Info]: connection: 2015-12-29 19:26:23.705--ServerSession(1275240546)--/file:/C:/Users/the-l/IdeaProjects/RefugEE3/out/production/RefugEE3/_RefugEEWelcomeApp login successful
ID : 1 Att: ... CAT: null
ID : 8 Att: ... CAT: null
...
这是我的 servlet:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("RefugEEWelcomeApp");
EntityManager em = emf.createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<TblProductCategoryEntity> query = builder.createQuery(TblProductCategoryEntity.class);
Root<TblProductCategoryEntity> productCategoryEntityRoot = query.from(TblProductCategoryEntity.class);
Predicate mainCatNull = builder.isNull(productCategoryEntityRoot.get(TblProductCategoryEntity_.maincategory));
query.select(productCategoryEntityRoot).where(mainCatNull);
List<TblProductCategoryEntity> results = em.createQuery(query).getResultList();
List<String> urls = new ArrayList<>();
List<Integer> subCat = new ArrayList<>();
for (Object o: results){
TblProductCategoryEntity e=(TblProductCategoryEntity) o;
urls.add(e.getAttachments());
subCat.add(e.getIdtblProductCategory());
System.out.println(e.getAttachments());
System.out.println(e.getIdtblProductCategory());
}
request.setAttribute("img", urls);
request.setAttribute("id", subCat);
getServletContext().getRequestDispatcher("/category.jsp").forward(request, response);
}
调用 servlet 的 TomEE 日志和浏览器输出:
HTTP Status 500 - Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
type Exception report
message Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: invalid schema name: REFUGEESWELCOMEAPP
Error Code: -4850
Call: SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: invalid schema name: REFUGEESWELCOMEAPP
Error Code: -4850
Call: SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.sql.SQLException: invalid schema name: REFUGEESWELCOMEAPP
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
com.sun.proxy.$Proxy86.prepareStatement(Unknown Source)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1565)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1514)
org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:778)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:621)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.hsqldb.HsqlException: invalid schema name: REFUGEESWELCOMEAPP
org.hsqldb.error.Error.error(Unknown Source)
org.hsqldb.error.Error.error(Unknown Source)
org.hsqldb.SchemaManager.getSchemaHsqlName(Unknown Source)
org.hsqldb.SchemaManager.getSchemaName(Unknown Source)
org.hsqldb.Session.getSchemaName(Unknown Source)
org.hsqldb.SchemaManager.getTable(Unknown Source)
org.hsqldb.ParserDQL.readTableName(Unknown Source)
org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
org.hsqldb.ParserCommand.compilePart(Unknown Source)
org.hsqldb.ParserCommand.compileStatement(Unknown Source)
org.hsqldb.Session.compileStatement(Unknown Source)
org.hsqldb.StatementManager.compile(Unknown Source)
org.hsqldb.Session.execute(Unknown Source)
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
com.sun.proxy.$Proxy86.prepareStatement(Unknown Source)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1565)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1514)
org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:778)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:621)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat (TomEE)/7.0.63 (1.7.3) logs.
Apache Tomcat (TomEE)/7.0.63 (1.7.3)
这张图是IntelliJ关于数据库的截图。
架构:RefugeesWelcomeApp
包括。所有表
问题:有人知道我的错是什么吗?
MariaDB 是上下文敏感的吗?如果是,如何管理?
或者 IntelliJ 是否有一些编译错误并为模式写了所有大字母?
编辑:如果我在模型中删除 class 架构标签,我会收到以下错误:
HTTP Status 500 - Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
type Exception report
message Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TBL_PRODUCT_CATEGORY
Error Code: -5501
Call: SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TBL_PRODUCT_CATEGORY
Error Code: -5501
Call: SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TBL_PRODUCT_CATEGORY
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...
percistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="RefugEEWelcomeApp" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>ra.model.RltnProductCategoryEntity</class>
<class>ra.model.RltnProductCategoryLanguageEntity</class>
<class>ra.model.RltnProductCategoryShopCategoryEntity</class>
<class>ra.model.RltnProductLanguageEntity</class>
<class>ra.model.RltnProductShopcategoryEntity</class>
<class>ra.model.RltnShopCategoryLanguageEntity</class>
<class>ra.model.TblLanguageEntity</class>
<class>ra.model.TblProductEntity</class>
<class>ra.model.TblProductCategoryEntity</class>
<class>ra.model.TblShopCategoryEntity</class>
<class>ra.model.TblShopsEntity</class>
<properties>
<property name="javax.persistence.logging.level" value="INFO"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/RefugeesWelcomeApp"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<servlet>
<description>Getting MainCat ID for Subcat searching</description>
<servlet-name>getMainCat</servlet-name>
<servlet-class>ra.servlets.getMainCategory</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getMainCat</servlet-name>
<url-pattern>/getMainCat</url-pattern>
</servlet-mapping>
</web-app>
Table class:
@Entity
@Table(name = "tbl_product_category", schema = "RefugeesWelcomeApp")
public class TblProductCategoryEntity {
private int idtblProductCategory;
private Integer maincategory;
private String attachments;
@Id
@Column(name = "idtbl_product_category")
public int getIdtblProductCategory() {
return idtblProductCategory;
}
public void setIdtblProductCategory(int idtblProductCategory) {
this.idtblProductCategory = idtblProductCategory;
}
@Basic
@Column(name = "maincategory")
public Integer getMaincategory() {
return maincategory;
}
public void setMaincategory(Integer maincategory) {
this.maincategory = maincategory;
}
@Basic
@Column(name = "attachments")
public String getAttachments() {
return attachments;
}
public void setAttachments(String attachments) {
this.attachments = attachments;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TblProductCategoryEntity that = (TblProductCategoryEntity) o;
if (idtblProductCategory != that.idtblProductCategory) return false;
if (maincategory != null ? !maincategory.equals(that.maincategory) : that.maincategory != null) return false;
if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false;
return true;
}
@Override
public int hashCode() {
int result = idtblProductCategory;
result = 31 * result + (maincategory != null ? maincategory.hashCode() : 0);
result = 31 * result + (attachments != null ? attachments.hashCode() : 0);
return result;
}
}
您似乎还没有配置使用 MySQL 后端的有效数据源。
org.hsqldb.HsqlException: invalid schema name: REFUGEESWELCOMEAPP
取而代之的是,TomEE 容器使用默认后端配置,该配置默认由 HSQLDB 驱动。这应该改变,看看:
- 关于如何在此处正确配置数据源的一般信息:tomee.apache.org/datasource-config.html 和
- 典型配置位于:tomee.apache.org/common-datasource-configurations.html
可以在 :
找到 working/similar 配置
<?xml version="1.0" encoding="utf-8"?>
<resources>
<Resource id="myDS-Name" type="javax.sql.DataSource">
JtaManaged = true
DataSourceCreator = tomcat
validationQuery = SELECT 1
initialSize = 2
removeAbandoned = true
removeAbandonedTimeout = 120
driverClassName = com.mysql.jdbc.Driver
url = jdbc:mysql://someFQDNHostnameOrIP/someDBname
username = your-username
password = your-pw
</Resource>
</resources>
我和一些学生有一个项目。 一个 RefugeeWelcome 网站:
- TomEE 1.7.3(Plume 版本)
- MariaDB:服务器版本:10.1.10-MariaDB-1~jessie-log mariadb.org 二进制分发
- IDE:IntelliJ IDEA 15.0.2
- JRE: 1.8.0_51
要从数据库中获取数据,我正在使用 Criteria API / JPA。
这里是工作的主要功能:
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("RefugEEWelcomeApp");
EntityManager em = emf.createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<TblProductCategoryEntity> query = builder.createQuery(TblProductCategoryEntity.class);
Root<TblProductCategoryEntity> productCategoryEntityRoot = query.from(TblProductCategoryEntity.class);
Predicate mainCatNull = builder.isNull(productCategoryEntityRoot.get(TblProductCategoryEntity_.maincategory));
query.select(productCategoryEntityRoot).where(mainCatNull);
List<TblProductCategoryEntity> results = em.createQuery(query).getResultList();
for(Object o:results)
{
TblProductCategoryEntity e=(TblProductCategoryEntity) o;
System.out.println(
"ID : "+e.getIdtblProductCategory()
+"\tAtt: "+e.getAttachments()
+"\tCAT: "+e.getMaincategory());
}
}
控制台输出:
[EL Info]: 2015-12-29 19:26:22.731--ServerSession(1275240546)--EclipseLink, version: Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3
[EL Info]: connection: 2015-12-29 19:26:23.705--ServerSession(1275240546)--/file:/C:/Users/the-l/IdeaProjects/RefugEE3/out/production/RefugEE3/_RefugEEWelcomeApp login successful
ID : 1 Att: ... CAT: null
ID : 8 Att: ... CAT: null
...
这是我的 servlet:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("RefugEEWelcomeApp");
EntityManager em = emf.createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<TblProductCategoryEntity> query = builder.createQuery(TblProductCategoryEntity.class);
Root<TblProductCategoryEntity> productCategoryEntityRoot = query.from(TblProductCategoryEntity.class);
Predicate mainCatNull = builder.isNull(productCategoryEntityRoot.get(TblProductCategoryEntity_.maincategory));
query.select(productCategoryEntityRoot).where(mainCatNull);
List<TblProductCategoryEntity> results = em.createQuery(query).getResultList();
List<String> urls = new ArrayList<>();
List<Integer> subCat = new ArrayList<>();
for (Object o: results){
TblProductCategoryEntity e=(TblProductCategoryEntity) o;
urls.add(e.getAttachments());
subCat.add(e.getIdtblProductCategory());
System.out.println(e.getAttachments());
System.out.println(e.getIdtblProductCategory());
}
request.setAttribute("img", urls);
request.setAttribute("id", subCat);
getServletContext().getRequestDispatcher("/category.jsp").forward(request, response);
}
调用 servlet 的 TomEE 日志和浏览器输出:
HTTP Status 500 - Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
type Exception report
message Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: invalid schema name: REFUGEESWELCOMEAPP
Error Code: -4850
Call: SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: invalid schema name: REFUGEESWELCOMEAPP
Error Code: -4850
Call: SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM RefugeesWelcomeApp.tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.sql.SQLException: invalid schema name: REFUGEESWELCOMEAPP
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
com.sun.proxy.$Proxy86.prepareStatement(Unknown Source)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1565)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1514)
org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:778)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:621)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.hsqldb.HsqlException: invalid schema name: REFUGEESWELCOMEAPP
org.hsqldb.error.Error.error(Unknown Source)
org.hsqldb.error.Error.error(Unknown Source)
org.hsqldb.SchemaManager.getSchemaHsqlName(Unknown Source)
org.hsqldb.SchemaManager.getSchemaName(Unknown Source)
org.hsqldb.Session.getSchemaName(Unknown Source)
org.hsqldb.SchemaManager.getTable(Unknown Source)
org.hsqldb.ParserDQL.readTableName(Unknown Source)
org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
org.hsqldb.ParserCommand.compilePart(Unknown Source)
org.hsqldb.ParserCommand.compileStatement(Unknown Source)
org.hsqldb.Session.compileStatement(Unknown Source)
org.hsqldb.StatementManager.compile(Unknown Source)
org.hsqldb.Session.execute(Unknown Source)
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
com.sun.proxy.$Proxy86.prepareStatement(Unknown Source)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1565)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1514)
org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:778)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:621)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat (TomEE)/7.0.63 (1.7.3) logs.
Apache Tomcat (TomEE)/7.0.63 (1.7.3)
这张图是IntelliJ关于数据库的截图。
架构:RefugeesWelcomeApp
包括。所有表
问题:有人知道我的错是什么吗? MariaDB 是上下文敏感的吗?如果是,如何管理? 或者 IntelliJ 是否有一些编译错误并为模式写了所有大字母?
编辑:如果我在模型中删除 class 架构标签,我会收到以下错误:
HTTP Status 500 - Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
type Exception report
message Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TBL_PRODUCT_CATEGORY
Error Code: -5501
Call: SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TBL_PRODUCT_CATEGORY
Error Code: -5501
Call: SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)
Query: ReadAllQuery(referenceClass=TblProductCategoryEntity sql="SELECT idtbl_product_category, attachments, maincategory FROM tbl_product_category WHERE (maincategory IS NULL)")
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
ra.servlets.getMainCategoryNative.doGet(getMainCategoryNative.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TBL_PRODUCT_CATEGORY
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...
percistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="RefugEEWelcomeApp" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>ra.model.RltnProductCategoryEntity</class>
<class>ra.model.RltnProductCategoryLanguageEntity</class>
<class>ra.model.RltnProductCategoryShopCategoryEntity</class>
<class>ra.model.RltnProductLanguageEntity</class>
<class>ra.model.RltnProductShopcategoryEntity</class>
<class>ra.model.RltnShopCategoryLanguageEntity</class>
<class>ra.model.TblLanguageEntity</class>
<class>ra.model.TblProductEntity</class>
<class>ra.model.TblProductCategoryEntity</class>
<class>ra.model.TblShopCategoryEntity</class>
<class>ra.model.TblShopsEntity</class>
<properties>
<property name="javax.persistence.logging.level" value="INFO"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/RefugeesWelcomeApp"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<servlet>
<description>Getting MainCat ID for Subcat searching</description>
<servlet-name>getMainCat</servlet-name>
<servlet-class>ra.servlets.getMainCategory</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getMainCat</servlet-name>
<url-pattern>/getMainCat</url-pattern>
</servlet-mapping>
</web-app>
Table class:
@Entity
@Table(name = "tbl_product_category", schema = "RefugeesWelcomeApp")
public class TblProductCategoryEntity {
private int idtblProductCategory;
private Integer maincategory;
private String attachments;
@Id
@Column(name = "idtbl_product_category")
public int getIdtblProductCategory() {
return idtblProductCategory;
}
public void setIdtblProductCategory(int idtblProductCategory) {
this.idtblProductCategory = idtblProductCategory;
}
@Basic
@Column(name = "maincategory")
public Integer getMaincategory() {
return maincategory;
}
public void setMaincategory(Integer maincategory) {
this.maincategory = maincategory;
}
@Basic
@Column(name = "attachments")
public String getAttachments() {
return attachments;
}
public void setAttachments(String attachments) {
this.attachments = attachments;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TblProductCategoryEntity that = (TblProductCategoryEntity) o;
if (idtblProductCategory != that.idtblProductCategory) return false;
if (maincategory != null ? !maincategory.equals(that.maincategory) : that.maincategory != null) return false;
if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false;
return true;
}
@Override
public int hashCode() {
int result = idtblProductCategory;
result = 31 * result + (maincategory != null ? maincategory.hashCode() : 0);
result = 31 * result + (attachments != null ? attachments.hashCode() : 0);
return result;
}
}
您似乎还没有配置使用 MySQL 后端的有效数据源。
org.hsqldb.HsqlException: invalid schema name: REFUGEESWELCOMEAPP
取而代之的是,TomEE 容器使用默认后端配置,该配置默认由 HSQLDB 驱动。这应该改变,看看:
- 关于如何在此处正确配置数据源的一般信息:tomee.apache.org/datasource-config.html 和
- 典型配置位于:tomee.apache.org/common-datasource-configurations.html
可以在
<?xml version="1.0" encoding="utf-8"?>
<resources>
<Resource id="myDS-Name" type="javax.sql.DataSource">
JtaManaged = true
DataSourceCreator = tomcat
validationQuery = SELECT 1
initialSize = 2
removeAbandoned = true
removeAbandonedTimeout = 120
driverClassName = com.mysql.jdbc.Driver
url = jdbc:mysql://someFQDNHostnameOrIP/someDBname
username = your-username
password = your-pw
</Resource>
</resources>