You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by catalina wei <ca...@gmail.com> on 2010/09/03 19:01:17 UTC

Re: StackOverflowError thrown on a selection with 2 subselects

Hi Savouillan,
This is likely a bug.
Which version of OpenJPA SNAPSHOT are you using ?
Could you provide entity source code for reproducing the problem ?
Thanks.

Catalina

On Tue, Aug 31, 2010 at 7:12 AM, Savouillan Lionel <ls...@axway.com>wrote:

> Hello,
>
>
>
> I encounter a StackOverflowError while running a simple selection. I'll
> try to explain as clearly as possible the context where the bug occurs:
>
>
>
> Here are my objects:
>
> A is persisted entity.
>
> A has a name field.
>
> A contains a tree structure of B.
>
> B is a persisted entity.
>
> B may have a B parent and may have B children.
>
> B has a name field.
>
> B has a path field which is build by collapsing all the parent names.
>
>
>
>
>
> Here is an example (syntax used: instanceName = className{attributeName:
> attributeValue, attributeName: attributeValue, ...};) :
>
> A = A{name: "A"};
>
> rootB = B{parentA: A, name: rootB};
>
> B1 = {parentA: A, name: "B1", parentB: rootB, path: "B1"};
>
> B11 = {parentA: A, name: "B11", parentB: B1, path: "B1.B11"};
>
> B12 = {parentA: A, name: "B12", parentB: B1, path: "B1.B12"};
>
> B111 = {parentA: A, name: "B11", parentB: B11, path: "B1.B11.B111"};
>
>
>
>
>
> Here is the query that I run:
>
> SELECT DISTINCT b from B b1, B b2 WHERE (LOCATE(b2.path, b1.path) = 1 OR
> b1.path = b2.path) AND (b2.name LIKE :arg1) AND (b1.parentA IN (SELECT
> DISTINCT a from A a WHERE a.name LIKE :arg2)) AND (b2.parentA IN (SELECT
> DISTINCT a from A a WHERE a.name LIKE :arg2))
>
>
>
>
>
> Here is the stacktrace:
>
> java.lang.StackOverflowError
>                at
> org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2132)
>                at
> org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2140)
>                at
> org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2132)
>                at
> org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2140)
>                at
> org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2132)
>                at
> org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2140)
>
>                at ...
>
>
>
> Here is the method into the JPA sources where the loop occurs:
>
> 2128:    /**
>
> 2129:     * Calculate total number of aliases.
>
> 2130:     */
>
> 2131:    private int aliasSize(SelectImpl fromSub) {
>
> 2132:        int aliases = (_parent == null) ? 0
>
> 2133:            : _parent.aliasSize(this);
>
> 2134:        aliases += (_aliases == null) ? 0 : _aliases.size();
>
> 2135:        if (_subsels != null) {
>
> 2136:            SelectImpl sub;
>
> 2137:            for (int i = 0; i < _subsels.size(); i++) {
>
> 2138:                sub = (SelectImpl) _subsels.get(i);
>
> 2139:                if (sub != fromSub)
>
> 2140:                    aliases += sub.aliasSize(null);
>
> 2141:            }
>
> 2142:        }
>
> 2143:        return aliases;
>
> 2144:    }
>
>
>
>
>
> The problem seems to occur when multiple subqueries are present.
>
> If I remove the second IN clause, the problem does not occur.
>
> I also suspect the problem occurs when multiple subqueries select the
> same object. I may be wrong, though.
>
>
>
> Any help is welcomed.
>
> Thanks.
>
>
>
> --
>
> Lionel Savouillan
>
>

RE: StackOverflowError thrown on a selection with 2 subselects

Posted by Savouillan Lionel <ls...@axway.com>.
Hi Wei,

 

We are using the OpenJPA 2.0.0.

 

Unfortunately, I cannot provide the source code of this class.

 

However, while investigating the problem, I noticed that some time ago,
the method in which the stack overflow problem occurs has been changed.

To be more specific, in the previous version of the SelectImpl class
(number 795934: 
http://fisheye6.atlassian.com/changelog/openjpa/?cs=795934
<http://fisheye6.atlassian.com/changelog/openjpa/?cs=795934> ), the
boolean "fromParent" was removed from the parameter list of the
aliasSize method.

I reverted the change on the aliasSize method and gave it a try.

It seemed to fix the problem.

 

I attached the updated source for you to double check. I was wondering
if this could be some kind of a regression.

 

What do you think?

 

Thanks.

 

Lionel.

 

From: catalina wei [mailto:catalina.wei@gmail.com] 
Sent: vendredi 3 septembre 2010 19:01
To: users@openjpa.apache.org; Savouillan Lionel
Subject: Re: StackOverflowError thrown on a selection with 2 subselects

 

Hi Savouillan,
This is likely a bug.
Which version of OpenJPA SNAPSHOT are you using ?
Could you provide entity source code for reproducing the problem ?
Thanks.

Catalina

On Tue, Aug 31, 2010 at 7:12 AM, Savouillan Lionel <
lsavouillan@axway.com> wrote:

Hello,



I encounter a StackOverflowError while running a simple selection. I'll
try to explain as clearly as possible the context where the bug occurs:



Here are my objects:

A is persisted entity.

A has a name field.

A contains a tree structure of B.

B is a persisted entity.

B may have a B parent and may have B children.

B has a name field.

B has a path field which is build by collapsing all the parent names.





Here is an example (syntax used: instanceName = className{attributeName:
attributeValue, attributeName: attributeValue, ...};) :

A = A{name: "A"};

rootB = B{parentA: A, name: rootB};

B1 = {parentA: A, name: "B1", parentB: rootB, path: "B1"};

B11 = {parentA: A, name: "B11", parentB: B1, path: "B1.B11"};

B12 = {parentA: A, name: "B12", parentB: B1, path: "B1.B12"};

B111 = {parentA: A, name: "B11", parentB: B11, path: "B1.B11.B111"};





Here is the query that I run:

SELECT DISTINCT b from B b1, B b2 WHERE (LOCATE(b2.path, b1.path) = 1 OR
b1.path = b2.path) AND (b2.name LIKE :arg1) AND (b1.parentA IN (SELECT
DISTINCT a from A a WHERE a.name LIKE :arg2)) AND (b2.parentA IN (SELECT
DISTINCT a from A a WHERE a.name LIKE :arg2))





Here is the stacktrace:

java.lang.StackOverflowError
               at
org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2132)
               at
org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2140)
               at
org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2132)
               at
org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2140)
               at
org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2132)
               at
org.apache.openjpa.jdbc.sql.SelectImpl.aliasSize(SelectImpl.java:2140)

               at ...



Here is the method into the JPA sources where the loop occurs:

2128:    /**

2129:     * Calculate total number of aliases.

2130:     */

2131:    private int aliasSize(SelectImpl fromSub) {

2132:        int aliases = (_parent == null) ? 0

2133:            : _parent.aliasSize(this);

2134:        aliases += (_aliases == null) ? 0 : _aliases.size();

2135:        if (_subsels != null) {

2136:            SelectImpl sub;

2137:            for (int i = 0; i < _subsels.size(); i++) {

2138:                sub = (SelectImpl) _subsels.get(i);

2139:                if (sub != fromSub)

2140:                    aliases += sub.aliasSize(null);

2141:            }

2142:        }

2143:        return aliases;

2144:    }





The problem seems to occur when multiple subqueries are present.

If I remove the second IN clause, the problem does not occur.

I also suspect the problem occurs when multiple subqueries select the
same object. I may be wrong, though.



Any help is welcomed.

Thanks.



--

Lionel Savouillan