Hi,
I'm trying to change one of my Active Objects queries to streams for better performance (see here for reference: http://blogs.atlassian.com/2011/09/activeobjects_streaming_api/).
I have not changed the model at all, just the query from a "find" to a callback like this:
long startTime = System.currentTimeMillis(); // AOTimePlan[] result = ao.find(AOTimePlan.class, search); // this is the old way final List<NewPlanTime> result = Lists.newArrayList(); ao.stream(AOTimePlan.class, search, new EntityStreamCallback<AOTimePlan, Integer>() // line 83 { @Override public void onRowRead(AOTimePlan t) { result.add(convertTimePlan(t)); } }); System.out.println("Time to get all plans: " + (System.currentTimeMillis()-startTime) + "ms");
And this is the error I get:
java.sql.SQLException: Column not found: ''''primary_key_field'''' at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.stream(EntityManagedActiveObjects.java:189) at com.atlassian.activeobjects.osgi.DelegatingActiveObjects.stream(DelegatingActiveObjects.java:96) 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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307) at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58) at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56) at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy1290.stream(Unknown Source) at com.tempoplugin.core.tql.search.TqlPlanningSearcher.search(TqlPlanningSearcher.java:83)
This is on HSQL. Any ideas?
Many thanks,
-Bjarni
Community moderators have prevented the ability to post new answers.
Looks like calling stream() with a Query requires the fields for the FROM clause to be set.
e.g.
ao.stream(SomeEntity.class, Query.select().where("issue_key = ?", issueKey),new EntityStreamCallback ...
will fail with the error however, the following will work:
ao.stream(SomeEntity.class, Query.select("*").where("issue_key = ?", issueKey),new EntityStreamCallback ...
So just adding the "*" to the select seems to fix it
Brilliant! This did it...
BTW: I'm selecting about 6000 records in my test. It took about 10 seconds with the "find" but about 100ms with the "stream". That's about 100 fold speed increase.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, I tried reproducing this issue without much success. Jonathan what does your "SomeEntity" class looks like?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think it has to do with having a number in your entity.
my entity looks like:
package com.example.ao; import net.java.ao.Entity; import net.java.ao.Preload; import net.java.ao.schema.Indexed; import net.java.ao.schema.NotNull; @Preload public interface SomeEntity extends Entity { @NotNull //must have a value public String getIssueKey(); public void setIssueKey(String key); @NotNull //must have a value public String getUsername(); public void setUsername(String name); @NotNull //must have a value public Double getRating(); public void setRating(Double rating); }
and my initial ao call that was failing was:
final List<SomeEntity> ratings = new ArrayList<SomeEntity>(); ao.stream(SomeEntity.class, Query.select().where("issue_key = ?", issueKey),new EntityStreamCallback<SomeEntity, Integer>() { @Override public void onRowRead(SomeEntity rating) { ratings.add(rating); } });
When I changed the query to Query.select("*") it started working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jonathan Doklovic [Atlassian], Have you tried calling stream with Query.select("*") in Confluence 5.8 (actually 5.8.1-beta2)? Because it's failing in my add-on: java.lang.IllegalArgumentException: fields must not contain '*' - got '*' at net.java.ao.Query.validateSelectFields(Query.java:378) at net.java.ao.Query.<init>(Query.java:82) at net.java.ao.Query.select(Query.java:365)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using the query fields works though
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As far as I understand, this
ao.stream(SomeEntity.class, Query.select("*").where("issue_key = ?", issueKey),new EntityStreamCallback ...
won't work on Confluence 5.8 due to the new Active Objects implementation. "SelectAll" and the "*" have been removed in net.java.ao.Query
You need to use the required fields of the entity
Query.select("ID, FIELD1, FIELD2, FIELDN")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gorka, And for the sake of completeness I want to mention that the same applies to the upcoming JIRA 7, i.e. no "*" in JIRA 7+.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Seems like there is no atlassian upgrade docs for active objects, for the removal of the "*" in query in JIRA 7 also seems like ao streamAll does not return @oneToMany fields anymore in JIRA 7. Thanks Bjarni.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.