我遇到了JPQL的问题......我试图用Vaadin,Shiro,MySQL,JPA创建一个Web应用程序......几年前我已经制作了一个桌面应用程序,并使用了所有的库来安装JPA来自那个项目。我有mysql-connector-java-5.0.8-bin.jar的问题。当我尝试运行该项目时,我成为一个SQL异常com.mysql.jdbc.driver未找到。很少有人遇到同样的问题并用5.1.17或更高版本替换mysql连接器5.0.8解决了这个问题。我做了这个,现在我遇到了一个新问题。
此查询正常工作:
TypedQuery<Products> q = em.createQuery("SELECT e FROM Products e",Products.class);
List<Products> products = q.getResultList();
此查询无效:
TypedQuery<Products> q = em.createQuery("SELECT e FROM Products e WHERE e.name LIKE 'something'",Products.class);
Products products = q.getSingleResult();
我成了这个例外:
15:45:25,879 INFO [stdout] (http-localhost-127.0.0.1-8080-1) Hibernate:
15:45:25,879 INFO [stdout] (http-localhost-127.0.0.1-8080-1) WITH query AS (select
15:45:25,880 INFO [stdout] (http-localhost-127.0.0.1-8080-1) product0_.idproduct as idproduct_495_,
15:45:25,880 INFO [stdout] (http-localhost-127.0.0.1-8080-1) product0_.name as name495_,
15:45:25,904 INFO [stdout] (http-localhost-127.0.0.1-8080-1) ROW_NUMBER() OVER (
15:45:25,905 INFO [stdout] (http-localhost-127.0.0.1-8080-1) ORDER BY
15:45:25,905 INFO [stdout] (http-localhost-127.0.0.1-8080-1) CURRENT_TIMESTAMP) as __hibernate_row_nr__
15:45:25,905 INFO [stdout] (http-localhost-127.0.0.1-8080-1) from
15:45:25,905 INFO [stdout] (http-localhost-127.0.0.1-8080-1) products product0_
15:45:25,906 INFO [stdout] (http-localhost-127.0.0.1-8080-1) where
15:45:25,906 INFO [stdout] (http-localhost-127.0.0.1-8080-1) product0_.name like 'something') SELECT
15:45:25,906 INFO [stdout] (http-localhost-127.0.0.1-8080-1) *
15:45:25,907 INFO [stdout] (http-localhost-127.0.0.1-8080-1) FROM
15:45:25,907 INFO [stdout] (http-localhost-127.0.0.1-8080-1) query
15:45:25,907 INFO [stdout] (http-localhost-127.0.0.1-8080-1) WHERE
15:45:25,907 INFO [stdout] (http-localhost-127.0.0.1-8080-1) __hibernate_row_nr__ >= ?
15:45:25,908 INFO [stdout] (http-localhost-127.0.0.1-8080-1) AND __hibernate_row_nr__ < ?
15:45:25,924 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) SQL Error: 1064, SQLState: 42000
15:45:25,924 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH query AS (select product0_.idproduct as idproduct_495_, product0_' at line 1
15:45:25,926 SEVERE [com.vaadin.server.DefaultErrorHandler] (http-localhost-127.0.0.1-8080-1) : javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH query AS (select product0_.idproduct as idproduct_495_, product0_' at line 1
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:313) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at com.vaadin.demo.dashboard.DashboardUI.init(DashboardUI.java:105) [classes:]
at com.vaadin.ui.UI.doInit(UI.java:610) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) [vaadin-server-7.1.6.jar:7.1.6]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_60]
Caused by: org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH query AS (select product0_.idproduct as idproduct_495_, product0_' at line 1
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at com.sun.proxy.$Proxy53.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1978) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:829) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2463) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2449) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.list(Loader.java:2274) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1115) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:280) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
... 34 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH query AS (product0_.idproduct as idproduct_495_, product0_' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_60]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.7.0_60]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.7.0_60]
at java.lang.reflect.Constructor.newInstance(Unknown Source) [rt.jar:1.7.0_60]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.Util.getInstance(Util.java:386) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281) [mysql-connector-java-5.1.17-bin.jar:]
at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:107)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_60]
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
... 49 more
15:45:25,971 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Dashboard].[VaadinServlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet VaadinServlet threw exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH query AS (product0_.idproduct as idproduct_495_, product0_' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_60]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.7.0_60]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.7.0_60]
at java.lang.reflect.Constructor.newInstance(Unknown Source) [rt.jar:1.7.0_60]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.Util.getInstance(Util.java:386) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) [mysql-connector-java-5.1.17-bin.jar:]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281) [mysql-connector-java-5.1.17-bin.jar:]
at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:107)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_60]
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at com.sun.proxy.$Proxy53.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1978) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:829) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2463) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2449) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.list(Loader.java:2274) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1115) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:280) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at com.vaadin.demo.dashboard.DashboardUI.init(DashboardUI.java:105) [classes:]
at com.vaadin.ui.UI.doInit(UI.java:610) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371) [vaadin-server-7.1.6.jar:7.1.6]
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) [vaadin-server-7.1.6.jar:7.1.6]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-all-1.2.1.jar:1.2.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_60]
谢谢...
编辑1 我已经测试了另一个查询,它也很好......
TypedQuery<Products> query1 = em.createQuery("SELECT e FROM Products e WHERE e.name LIKE 'something' OR e.name LIKE 'somethingElse' ",Products.class);
List<Products> list = query1.getResultList();
哪里声明不是问题。问题是getSingleResult,但我不知道如何解决它... 谢谢......
答案 0 :(得分:0)
你想尝试
TypedQuery<Products> q = em.createQuery("SELECT e FROM Products e WHERE e.name LIKE :something ",Products.class);
q.setParameter("something ", something );
Products products = q.getSingleResult();
答案 1 :(得分:0)
Products products = em.createQuery("SELECT e FROM Products e WHERE e.name = :name1 OR e.name = :name2", Products.class).setParameter("name1", "value1").setParameter("name2", "value2").getSingleResult();
OR
Products products = em.createQuery("SELECT e FROM Products e WHERE (e.name LIKE :name1) OR (e.name LIKE :name2)", Products.class).setParameter("name1", "value1").setParameter("name2", "value2").getSingleResult();
您必须记住JPQL的语法。在WHERE子句中,如果传递参数,则可以添加两个运算符:=和:,其中= sign是赋值符号,并且:是下一个将有传递参数名称的信息(:parameter_name)