Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Query caching for report queries?

Since posting this I have discovered through trial and error and a little reading of the documentation spread out over the wiki that if I invoke both cacheQueryResults() as wel as returnSingleValue() on the report query, the error no longer occurs, but the results are not cached either.  Executing the query 5 times in a row results in 5 separate queries to the db and 5 separate result set fetches from the db :(

The following code (which contains no explicit cache parameter settings or cache invalidation policies) illustrates what I'm working with to build the query:

            ReportQuery query1 = new ReportQuery(Message.class, new ExpressionBuilder());
            query1.returnSingleValue();
            query1.addCount();
            query1.prepareForExecution();
            query1.cacheQueryResults();
            
            for (int i = 0; i < 5; i++) {
                int  messageCount = (Integer)session.executeQuery(query1);
                System.out.println(messageCount);
            }


On Fri, Oct 15, 2010 at 3:34 AM, Phillip Ross <phillip.w.g.ross@xxxxxxxxx> wrote:
Posting this to the correct list may get better response :)


Hi all... does eclipselink support caching results of report queries?  I could swear I've done this in the past but attempting with a recent eclipselink v2.1.1 and some JPA code I was getting an odd error.  Since The previous times I've worked with query caching it was with older versions of toplink/eclipselink that did not use JPA, but used the native query interface.

I reimplemented code as native eclipselink queries and oddly I get the same error.  Error and fullstack trace follow, but the error only occurs when caching has been turned on for the query, otherwise it works fine and returns results, albeit it generating db queries and retrieving results from the db on every query execution.

Exception [EclipseLink-26] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Trying to get value for instance variable [id] of type [long] from the object [org.eclipse.persistence.queries.ReportQueryResult].  The specified object is not an instance of the class or interface declaring the underlying field.
Internal Exception: java.lang.IllegalArgumentException: Can not set long field com.phillipross.testing.model.Message.id to org.eclipse.persistence.queries.ReportQueryResult
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[id-->MESSAGE.ID]
Descriptor: RelationalDescriptor(com.phillipross.testing.model.Message --> [DatabaseTable(MESSAGE)])
        at org.eclipse.persistence.exceptions.DescriptorException.illegalArgumentWhileGettingValueThruInstanceVariableAccessor(DescriptorException.java:629)
        at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:79)
        at org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(DatabaseMapping.java:497)
        at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.valueFromObject(AbstractDirectMapping.java:1218)
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromObject(ObjectBuilder.java:2133)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerExistingObject(UnitOfWorkImpl.java:3936)
        at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:368)
        at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1112)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2909)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1291)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1273)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1233)
        at com.phillipross.testing.TestPersistence.testJpa(TestPersistence.java:53)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:640)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:627)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:799)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1103)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:137)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:121)
        at org.testng.TestRunner.runWorkers(TestRunner.java:1098)
        at org.testng.TestRunner.privateRun(TestRunner.java:727)
        at org.testng.TestRunner.run(TestRunner.java:581)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:315)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:310)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:272)
        at org.testng.SuiteRunner.run(SuiteRunner.java:221)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:40)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:83)
        at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:151)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.IllegalArgumentException: Can not set long field com.phillipross.testing.model.Message.id to org.eclipse.persistence.queries.ReportQueryResult
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
        at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
        at sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:42)
        at sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:18)
        at java.lang.reflect.Field.get(Field.java:358)
        at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:76)
        ... 34 more


Back to the top