Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA 2.0 and MySQL 5.1 ERROR(A query on MySQL executes fine, same query with JPA throws an error)
JPA 2.0 and MySQL 5.1 ERROR [message #505610] Sun, 03 January 2010 13:24 Go to next message
No real name is currently offline No real nameFriend
Messages: 4
Registered: December 2009
Junior Member
Hi,

In one of my JPA 2.0 entities I have this query:

@NamedNativeQueries({@NamedNativeQuery(name = "CustomItem.count", query = "SELECT IFNULL( (SELECT MAX(customItemId) FROM CUSTOMITEM) ,1)")})

and the Java code that uses it is:

int noOfCustomItems = (Integer)entityManager.createNativeQuery("CustomItem.count").getSingleResult();

The sql code of the NamedNativeQuery :

SELECT IFNULL( (SELECT MAX(customItemId) FROM CUSTOMITEM) ,1)

executes just fine from the mysql command line prompt, but exactly the same code executed by JPA 2.0, throws this exception :

Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal 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 'CustomItem.count' at line 1
Error Code: 1064
Call: CustomItem.count
Query: DataReadQuery(sql="CustomItem.count")
at org.eclipse.persistence.exceptions.DatabaseException.sqlExce ption(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:686)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeCall(DatabaseAccessor.java:529)
at org.eclipse.persistence.sessions.server.ServerSession.execut eCall(ServerSession.java:529)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:205)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:191)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeSelectCall(DatasourceCallQueryMechanism.jav a:262)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeSelect(DatasourceCallQueryMechanism.java:24 4)
at org.eclipse.persistence.queries.DataReadQuery.executeNonCurs or(DataReadQuery.java:188)
at org.eclipse.persistence.queries.DataReadQuery.executeDatabas eQuery(DataReadQuery.java:144)
at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:675)
at org.eclipse.persistence.queries.DataReadQuery.execute(DataRe adQuery.java:130)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:589)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1181)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeRea dQuery(EJBQueryImpl.java:453)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleR esult(EJBQueryImpl.java:702)
at bogdan.shop.dao.DAO.createCustomItem(DAO.java:460)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.ru nMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.in voke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseCo ntainer.java:5243)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.jav a:615)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.in vokeNext(InterceptorManager.java:797)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.d oAround(SystemInterceptorProxy.java:157)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.a roundInvoke(SystemInterceptorProxy.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor. intercept(InterceptorManager.java:858)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.in vokeNext(InterceptorManager.java:797)
at com.sun.ejb.containers.interceptors.InterceptorManager.inter cept(InterceptorManager.java:367)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContain er.java:5215)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer .java:5203)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invok e(EJBLocalObjectInvocationHandler.java:190)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelega te.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy129.createCustomItem(Unknown Source)
at bogdan.shop.dao.__EJB31_Generated__DAO__Intf____Bean__.creat eCustomItem(Unknown Source)
at bogdan.shop.controller.user.CreateUpdateCustomItemServlet.pr ocessRequest(CreateUpdateCustomItemServlet.java:34)
at bogdan.shop.controller.user.CreateUpdateCustomItemServlet.do Post(CreateUpdateCustomItemServlet.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWra pper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(Standar dWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(Standar dContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPip eline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:9 7)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invo ke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHo stValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(Coyote Adapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd apter.java:233)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service( ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTa sk.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.j ava:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.jav a:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultPr otocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(D efaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocol Chain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocol Chain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolC hain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChai nContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyCon textTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(Abstra ctThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractT hreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
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 'CustomItem.count' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:5 13)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:103 0)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956 )
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:25 42)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta tement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatem ent.java:1885)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeSelect(DatabaseAccessor.java:891)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:601)
... 71 more
|#]
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException( BaseContainer.java:5070)
at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(Base Container.java:4899)
at com.sun.ejb.containers.BaseContainer.checkExceptionBeanMgTx( BaseContainer.java:4820)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContai ner.java:4720)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContaine r.java:1955)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContaine r.java:1906)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invok e(EJBLocalObjectInvocationHandler.java:198)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelega te.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy129.createCustomItem(Unknown Source)
at bogdan.shop.dao.__EJB31_Generated__DAO__Intf____Bean__.creat eCustomItem(Unknown Source)
at bogdan.shop.controller.user.CreateUpdateCustomItemServlet.pr ocessRequest(CreateUpdateCustomItemServlet.java:34)
at bogdan.shop.controller.user.CreateUpdateCustomItemServlet.do Post(CreateUpdateCustomItemServlet.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWra pper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(Standar dWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(Standar dContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPip eline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:9 7)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invo ke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHo stValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(Coyote Adapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd apter.java:233)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service( ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTa sk.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.j ava:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.jav a:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultPr otocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(D efaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocol Chain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocol Chain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolC hain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChai nContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyCon textTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(Abstra ctThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractT hreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal 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 'CustomItem.count' at line 1
Error Code: 1064
Call: CustomItem.count
Query: DataReadQuery(sql="CustomItem.count")
at org.eclipse.persistence.exceptions.DatabaseException.sqlExce ption(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:686)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeCall(DatabaseAccessor.java:529)
at org.eclipse.persistence.sessions.server.ServerSession.execut eCall(ServerSession.java:529)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:205)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:191)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeSelectCall(DatasourceCallQueryMechanism.jav a:262)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeSelect(DatasourceCallQueryMechanism.java:24 4)
at org.eclipse.persistence.queries.DataReadQuery.executeNonCurs or(DataReadQuery.java:188)
at org.eclipse.persistence.queries.DataReadQuery.executeDatabas eQuery(DataReadQuery.java:144)
at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:675)
at org.eclipse.persistence.queries.DataReadQuery.execute(DataRe adQuery.java:130)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:589)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1181)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeRea dQuery(EJBQueryImpl.java:453)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleR esult(EJBQueryImpl.java:702)
at bogdan.shop.dao.DAO.createCustomItem(DAO.java:460)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.ru nMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.in voke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseCo ntainer.java:5243)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.jav a:615)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.in vokeNext(InterceptorManager.java:797)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.d oAround(SystemInterceptorProxy.java:157)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.a roundInvoke(SystemInterceptorProxy.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor. intercept(InterceptorManager.java:858)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.in vokeNext(InterceptorManager.java:797)
at com.sun.ejb.containers.interceptors.InterceptorManager.inter cept(InterceptorManager.java:367)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContain er.java:5215)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer .java:5203)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invok e(EJBLocalObjectInvocationHandler.java:190)
... 31 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 'CustomItem.count' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:5 13)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:103 0)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956 )
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:25 42)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta tement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatem ent.java:1885)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeSelect(DatabaseAccessor.java:891)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:601)
... 71 more
|#]
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException( BaseContainer.java:5070)
at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(Base Container.java:4899)
at com.sun.ejb.containers.BaseContainer.checkExceptionBeanMgTx( BaseContainer.java:4820)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContai ner.java:4720)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContaine r.java:1955)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContaine r.java:1906)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invok e(EJBLocalObjectInvocationHandler.java:198)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelega te.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy129.createCustomItem(Unknown Source)
at bogdan.shop.dao.__EJB31_Generated__DAO__Intf____Bean__.creat eCustomItem(Unknown Source)
at bogdan.shop.controller.user.CreateUpdateCustomItemServlet.pr ocessRequest(CreateUpdateCustomItemServlet.java:34)
at bogdan.shop.controller.user.CreateUpdateCustomItemServlet.do Post(CreateUpdateCustomItemServlet.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWra pper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(Standar dWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(Standar dContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPip eline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:9 7)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invo ke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHo stValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(Coyote Adapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd apter.java:233)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service( ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTa sk.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.j ava:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.jav a:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultPr otocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(D efaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocol Chain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocol Chain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolC hain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChai nContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyCon textTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(Abstra ctThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractT hreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal 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 'CustomItem.count' at line 1
Error Code: 1064
Call: CustomItem.count
Query: DataReadQuery(sql="CustomItem.count")
at org.eclipse.persistence.exceptions.DatabaseException.sqlExce ption(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:686)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeCall(DatabaseAccessor.java:529)
at org.eclipse.persistence.sessions.server.ServerSession.execut eCall(ServerSession.java:529)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:205)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:191)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeSelectCall(DatasourceCallQueryMechanism.jav a:262)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeSelect(DatasourceCallQueryMechanism.java:24 4)
at org.eclipse.persistence.queries.DataReadQuery.executeNonCurs or(DataReadQuery.java:188)
at org.eclipse.persistence.queries.DataReadQuery.executeDatabas eQuery(DataReadQuery.java:144)
at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:675)
at org.eclipse.persistence.queries.DataReadQuery.execute(DataRe adQuery.java:130)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:589)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1181)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeRea dQuery(EJBQueryImpl.java:453)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleR esult(EJBQueryImpl.java:702)
at bogdan.shop.dao.DAO.createCustomItem(DAO.java:460)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.ru nMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.in voke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseCo ntainer.java:5243)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.jav a:615)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.in vokeNext(InterceptorManager.java:797)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.d oAround(SystemInterceptorProxy.java:157)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.a roundInvoke(SystemInterceptorProxy.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor. intercept(InterceptorManager.java:858)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.in vokeNext(InterceptorManager.java:797)
at com.sun.ejb.containers.interceptors.InterceptorManager.inter cept(InterceptorManager.java:367)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContain er.java:5215)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer .java:5203)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invok e(EJBLocalObjectInvocationHandler.java:190)
... 31 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 'CustomItem.count' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:5 13)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:103 0)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956 )
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:25 42)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta tement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatem ent.java:1885)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeSelect(DatabaseAccessor.java:891)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:601)
... 71 more
|#]



Is this a bug, or am I missing something?
Re: JPA 2.0 and MySQL 5.1 ERROR [message #505749 is a reply to message #505610] Mon, 04 January 2010 18:46 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Your are calling the wrong method,

createNativeQuery(String sql)

this creates a "new" query using the "sql"

You want,

createNamedQuery(String name)

You are executing "CustomItem.count" as the MySQL error is telling you.


James : Wiki : Book : Blog : Twitter
Previous Topic:Workbench and Object-relational nested table mappings
Next Topic:Problem with sdo in OSGi bundle (classloader?)
Goto Forum:
  


Current Time: Wed Nov 26 23:23:44 GMT 2014

Powered by FUDForum. Page generated in 0.02316 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software