Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Error when streaming Active Objects data with a callback

Bjarni Thorbjornsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2012

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

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
brainicorn
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 10, 2012

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

Bjarni Thorbjornsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

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.

Samuel Le Berrigaud
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 11, 2012

Hmm, I tried reproducing this issue without much success. Jonathan what does your "SomeEntity" class looks like?

brainicorn
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 11, 2012

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

Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 12, 2015

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)

Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 12, 2015

Using the query fields works though

0 votes
Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 12, 2015

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

https://bitbucket.org/activeobjects/ao/src/919d26151b3cf94f289295562404dfd24ecb5248/activeobjects-core/src/net/java/ao/Query.java?at=master#cl-378

You need to use the required fields of the entity

Query.select("ID, FIELD1, FIELD2, FIELDN")
Bjarni Thorbjornsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2015

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+.

Jean Jean October 13, 2015

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.

TAGS
AUG Leaders

Atlassian Community Events