Bug #58183 JpaCluster can not handle EntityManager.createNativeQuerie()
Submitted: 14 Nov 2010 14:21 Modified: 16 Dec 2011 20:55
Reporter: Nicolas Seyvet Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Cluster: Cluster/J Severity:S2 (Serious)
Version:mysql-5.1-telco-7.1 OS:Linux (Ubuntu maverick)
Assigned to: CPU Architecture:Any
Tags: JpaCluster native query 7.1.8
Triage: Triaged: D2 (Serious) / R6 (Needs Assessment) / E6 (Needs Assessment)

[14 Nov 2010 14:21] Nicolas Seyvet
Description:
String query = "SELECT ID FROM SMALLEMPLOYEE ORDER BY RAND() LIMIT 1";
        List<Long> ids = new ArrayList<Long>(max);
        for (int i = 0; i < max; i++) {
            Query q = em.createNativeQuery(query);
            ids.add((Long) q.getSingleResult());
        }

Using persistence.xml:
<persistence-unit name="BM" transaction-type="JTA">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <jta-data-source>jdbc/bm</jta-data-source>
        <class>persist.BigCompany</class>
        <class>persist.SmallEmployee</class>
        <properties>
            <property name="openjpa.BrokerFactory" value="ndb"/>
            <property name="openjpa.ndb.connectString" value="localhost:1186"/>
            <property name="openjpa.jdbc.SynchronizeMappings"
                      value="buildSchema(SchemaAction='add')"/>            
            <property name="openjpa.jdbc.DBDictionary" value="TableType=ndb" />
            <property name="openjpa.ConnectionRetainMode" value="transaction"/>
            <property name="openjpa.ndb.database" value="bm"/>
            <property name="openjpa.ndb.connectVerbose" value="0"/>
            <property name="openjpa.DataCache" value="false"/>
        </properties>
    </persistence-unit>

Generates the following exception:

Caused by: <openjpa-1.2.2-r422266:898935 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
	at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:610)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:795)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:771)
	at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:517)
	at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:255)
	at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:317)
	at com.sun.enterprise.util.QueryWrapper.getSingleResult(QueryWrapper.java:212)
	at loader.MyLoader.getSmallEmployees(MyLoader.java:192)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
	at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
	at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2929)
	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4020)
	at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:190)
	... 62 more
Caused by: java.lang.NullPointerException
	at org.apache.openjpa.kernel.ExpressionStoreQuery.newCompilation(ExpressionStoreQuery.java:149)
	at org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:657)
	at org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:639)
	at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:605)
	... 79 more
|#]

How to repeat:
See above...

Full exception

javax.ejb.EJBException
	at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3903)
	at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(BaseContainer.java:3735)
	at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3583)
	at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:201)
	at $Proxy225.getSmallEmployees(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at com.sun.enterprise.webservice.InvokerImpl.invoke(InvokerImpl.java:78)
	at com.sun.enterprise.webservice.EjbInvokerImpl.invoke(EjbInvokerImpl.java:82)
	at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
	at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
	at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
	at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
	at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
	at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
	at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
	at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
	at com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:147)
	at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
	at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
	at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
	at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
	at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
	at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
	at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:222)
	at com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:133)
	at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
	at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
	at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
	at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
	at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
	at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
	at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
	at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
	at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
	at com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:113)
	at com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
	at com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:231)
	at com.sun.enterprise.webservice.EjbWebServiceServlet.service(EjbWebServiceServlet.java:157)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
	at com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java:114)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:87)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:291)
	at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:666)
	at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:597)
	at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872)
	at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
	at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
	at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
	at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264)
	at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:117)
Caused by: <openjpa-1.2.2-r422266:898935 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
	at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:610)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:795)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:771)
	at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:517)
	at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:255)
	at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:317)
	at com.sun.enterprise.util.QueryWrapper.getSingleResult(QueryWrapper.java:212)
	at loader.MyLoader.getSmallEmployees(MyLoader.java:192)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
	at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
	at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2929)
	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4020)
	at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:190)
	... 62 more
Caused by: java.lang.NullPointerException
	at org.apache.openjpa.kernel.ExpressionStoreQuery.newCompilation(ExpressionStoreQuery.java:149)
	at org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:657)
	at org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:639)
	at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:605)
	... 79 more
|#]

Suggested fix:
My guess is that the problem is that the native query does not match with the DBDictionary.  Which makes OpenJPA crash.  The other option is that native queries are not supported by JPACluster.
[16 Dec 2010 21:52] Sveta Smirnova
Thank you for the report.

Please send us output of SHOW CREATE TABLE SMALLEMPLOYEE
[17 Dec 2010 13:22] Nicolas Seyvet
CREATE TABLE `SMALLEMPLOYEE` (/n  `id` bigint(20) NOT NULL,/n  `name` varchar(255) DEFAULT NULL,/n  `version` int(11) DEFAULT NULL,/n  `COMP_ID` bigint(20) NOT NULL,/n  PRIMARY KEY (`id`),/n  KEY `I_SMLLPLY_COMPANY` (`COMP_ID`)/n) ENGINE=ndbcluster DEFAULT CHARSET=latin1
[26 Oct 2011 11:48] Anton Snider
No update on this issue so far?
[16 Dec 2011 20:53] Sveta Smirnova
test case

Attachment: bug58183.tar (application/x-tar, text), 130.00 KiB.

[16 Dec 2011 20:55] Sveta Smirnova
Thank you for the feedback.

Verified as described.