You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Misha Doronin (JIRA)" <ji...@apache.org> on 2010/09/24 16:14:34 UTC

[jira] Created: (CAY-1484) Flattened attribute queries are incorrectly generated

Flattened attribute queries are incorrectly generated
-----------------------------------------------------

                 Key: CAY-1484
                 URL: https://issues.apache.org/jira/browse/CAY-1484
             Project: Cayenne
          Issue Type: Bug
          Components: Core Library
    Affects Versions: 3.0.1
         Environment: Gentoo linux
MySQL 5.1
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
            Reporter: Misha Doronin


Attached eclipse project demonstrating issue, including cayenne model
When creating database structure like:
table1
  t1key
  t1value
  t2keyref
table2
  t2key
  t2value
  t3keyref
table3
  t3key
  t3value
and cayenne model with flattened attribute table3.t3value in table2
it produces incorrect join query to table2 and 3:
SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?

Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Ksenia Khailenko (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919261#action_12919261 ] 

Ksenia Khailenko commented on CAY-1484:
---------------------------------------

The problem was in incorrect using of aliases during the translation of the select query. 
The name of flattened attribute, that is longer than name of corresponding db attribute, forced the order of declaredProperties in PersistentDescriptor as {"flattened attribute","some obj relationship",...}. And when the visitor worked, the processing of "flattened attribute" gave alias "t1", that was used also for the source attribute of "some obj relationship", because there was not the resetting of join stack after the processing of "flattened attribute". The patch with the unit test and the fix is attached

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CAY-1484.-Fixed-using-of-incorrect-alias.patch, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Misha Doronin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Misha Doronin updated CAY-1484:
-------------------------------

    Attachment: bugdemo_maven_derby.zip
                bugdemo_maven_derby_nobug.zip

As you requested, here it goes.
In fact it depends on the order you generate classes in modeler, and in the order dependencies are placed in BugDemoMap.map.xml
See 
diff -u bugdemo/src/main/resources/BugDemoMap.map.xml bugdemo_nobug/src/main/resources/BugDemoMap.map.xml

And in "bug" configuration, there is commented out line in Main.java, which if enabled, causes null pointer exception.

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Ksenia Khailenko (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914806#action_12914806 ] 

Ksenia Khailenko commented on CAY-1484:
---------------------------------------

Ok, I've solved the problem in bugdemo project by changing the flattened attribute Album.ArtistName name from "ArtistName" to "artistName" and regenerating the classes(btw, the regeneration of classes also solved the NPE problem with the commented line in Main - you've changed the Artist.albumsRel to Artist.albumRel in datamap, but forgotten to regenerate Artist java class).

But such a solution didn't explain the error in CayenneBugDemo - the flattened attribute l3value starts with lowercase letter. I've played with naming of attributes and discovered, that for the correct query generation name of the flattened attribute must match the name of the referring db attribute: "artistName" in case of bugdemo and "l3val" in case of CayenneBugDemo.

So, this is the bug and SelectTranslator should be checked in place where it generates aliases and columns for the flattened attributes(It seems like the relationships are added basing on the incorrect attribute name )

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Ksenia Khailenko (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914543#action_12914543 ] 

Ksenia Khailenko commented on CAY-1484:
---------------------------------------

Really, in described situation(using datamap of the project attached), the sql string is generated incorrectly:
new SelectQuery(L2table.class) produces:
SELECT t1.l3val, t1.l2pk, t0.l2value, t0.l3fk, t0.l2pk FROM l2table t0 JOIN l3table t1 ON (t0.l3fk = t1.l3pk)

and t1.l2pk is used instead of t1.l2fk
I've debugged this query evaluation and discovered that this column is generated in such a way because in org.apache.cayenne.access.trans.SelectTranslator.appendQueryColumns[313].PropertyVisitor.visitRelationship[366] there is considered the relationship between table1 and table2, but not between table2 and table3 as expected. So, it's strange why it uses incorrect alias and skips the join between table2 and table1 in from section. need to investigate deeper. seems like incorrectly defined relationship is used.

Misha, could you be so kind to name the entities more intuitive understandable then they are now?) it's very hard to understand what it it incorrect in the relationship if we are using just numbered names. And as for the attached project - could you make this project like it is described in http://cayenne.apache.org/doc30/tutorial-starting-project.html? there's used inMemory db and maven, so we would be not dependent on libraries and schema. 

Regards, Ksenia

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Misha Doronin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Misha Doronin updated CAY-1484:
-------------------------------

    Attachment: CayenneBugDemo.zip

Eclipse project to demonstrate bug
Database dump and cayenne project are included.

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Misha Doronin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914666#action_12914666 ] 

Misha Doronin edited comment on CAY-1484 at 9/24/10 7:31 PM:
-------------------------------------------------------------

As you requested, here it goes.
Two configurations, one worknig, one not.

And in "bug" configuration, there is commented out line in Main.java, which if enabled, causes null pointer exception.

The meaningful difference seems to be in fact that in broken configuration two different relationships have the same name.

      was (Author: misdoro):
    As you requested, here it goes.
Two configurations, one worknig, one not.

And in "bug" configuration, there is commented out line in Main.java, which if enabled, causes null pointer exception.
  
> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Andrus Adamchik (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik closed CAY-1484.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 3.1M1
                   3.0.2

closing this, as it is already fixed on 3.0 and 3.1 branches

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>             Fix For: 3.0.2, 3.1M1
>
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CAY-1484.-Fixed-using-of-incorrect-alias.patch, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Misha Doronin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914666#action_12914666 ] 

Misha Doronin edited comment on CAY-1484 at 9/24/10 6:55 PM:
-------------------------------------------------------------

As you requested, here it goes.
Two configurations, one worknig, one not.

And in "bug" configuration, there is commented out line in Main.java, which if enabled, causes null pointer exception.

      was (Author: misdoro):
    As you requested, here it goes.
In fact it depends on the order you generate classes in modeler, and in the order dependencies are placed in BugDemoMap.map.xml
See 
diff -u bugdemo/src/main/resources/BugDemoMap.map.xml bugdemo_nobug/src/main/resources/BugDemoMap.map.xml

And in "bug" configuration, there is commented out line in Main.java, which if enabled, causes null pointer exception.
  
> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Updated: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by Andrus Adamchik <an...@objectstyle.org>.
Xenia,

I saw your commit - thanks, and congrats on your first Cayenne commit in the new role :-)

A few notes:

1. We log all fixed Jiras under docs/doc/src/main/resources/RELEASE-NOTES.txt . Once this is done, you can go ahead and close the Jira.

2. Since we support 2 Cayenne branches - 3.0 and 3.1 (== trunk), all fixes to 3.0 should also be cloned to trunk, so that they do not disappear from the future releases.

Cheers,
Andrus



On Oct 9, 2010, at 11:51 PM, Andrus Adamchik wrote:

> Hi Xenia,
> 
> Thanks for looking into this. I reviewed the patch - looks correct to me (the unit test fails with an error before changes to SelectTranslator, and passes after doing the join stack reset), so please feel free to use your new committer powers to apply it. A few notes:
> 
> (1) Don't forget to add the newly generated CompoundPaintingLongNames.java and _CompoundPaintingLongNames.java (not included in the patch). 
> 
> (2) I think we may even go with a more general fix - instead of conditionally resetting the stack after a flattened attribute, always do a reset before any attribute or relationship:
> 
> diff --git a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java b/framework/cayen
> index 4ddee21..0d1c64f 100644
> --- a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
> +++ b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
> @@ -364,6 +365,8 @@ public class SelectTranslator extends QueryAssembler {
>             }
> 
>             private void visitRelationship(ArcProperty property) {
> +                resetJoinStack();
> +                
>                 ObjRelationship rel = property.getRelationship();
>                 DbRelationship dbRel = rel.getDbRelationships().get(0);
> 
> The reset is a rather cheap operation, and the above seems to be just a little more consistent (hmm... I wonder if not resetting it inside 'visitRelationship' would result in bugs similar to CAY-1484 for entities with multiple flattened relationships??)
> 
> Andrus 
> 
> 
> 
> On Oct 8, 2010, at 3:23 PM, Ksenia Khailenko (JIRA) wrote:
> 
>> 
>>    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
>> 
>> Ksenia Khailenko updated CAY-1484:
>> ----------------------------------
>> 
>>   Attachment: CAY-1484.-Fixed-using-of-incorrect-alias.patch
>> 
>>> Flattened attribute queries are incorrectly generated
>>> -----------------------------------------------------
>>> 
>>>               Key: CAY-1484
>>>               URL: https://issues.apache.org/jira/browse/CAY-1484
>>>           Project: Cayenne
>>>        Issue Type: Bug
>>>        Components: Core Library
>>>  Affects Versions: 3.0.1
>>>       Environment: Gentoo linux
>>> MySQL 5.1
>>> java version "1.6.0_20"
>>> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
>>> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>>>          Reporter: Misha Doronin
>>>       Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CAY-1484.-Fixed-using-of-incorrect-alias.patch, CayenneBugDemo.zip
>>> 
>>> Original Estimate: 1h
>>> Remaining Estimate: 1h
>>> 
>>> Attached eclipse project demonstrating issue, including cayenne model
>>> When creating database structure like:
>>> table1
>>> t1key
>>> t1value
>>> t2keyref
>>> table2
>>> t2key
>>> t2value
>>> t3keyref
>>> table3
>>> t3key
>>> t3value
>>> and cayenne model with flattened attribute table3.t3value in table2
>>> it produces incorrect join query to table2 and 3:
>>> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
>>> Note t1.t2key, which obviously shouldn't be there and produces error.
>> 
>> -- 
>> This message is automatically generated by JIRA.
>> -
>> You can reply to this email to add a comment to the issue online.
>> 
>> 
> 
> 


Re: [jira] Updated: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Xenia,

Thanks for looking into this. I reviewed the patch - looks correct to me (the unit test fails with an error before changes to SelectTranslator, and passes after doing the join stack reset), so please feel free to use your new committer powers to apply it. A few notes:

(1) Don't forget to add the newly generated CompoundPaintingLongNames.java and _CompoundPaintingLongNames.java (not included in the patch). 

(2) I think we may even go with a more general fix - instead of conditionally resetting the stack after a flattened attribute, always do a reset before any attribute or relationship:

diff --git a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java b/framework/cayen
index 4ddee21..0d1c64f 100644
--- a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
+++ b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
@@ -364,6 +365,8 @@ public class SelectTranslator extends QueryAssembler {
             }
 
             private void visitRelationship(ArcProperty property) {
+                resetJoinStack();
+                
                 ObjRelationship rel = property.getRelationship();
                 DbRelationship dbRel = rel.getDbRelationships().get(0);

The reset is a rather cheap operation, and the above seems to be just a little more consistent (hmm... I wonder if not resetting it inside 'visitRelationship' would result in bugs similar to CAY-1484 for entities with multiple flattened relationships??)

Andrus 



On Oct 8, 2010, at 3:23 PM, Ksenia Khailenko (JIRA) wrote:

> 
>     [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
> 
> Ksenia Khailenko updated CAY-1484:
> ----------------------------------
> 
>    Attachment: CAY-1484.-Fixed-using-of-incorrect-alias.patch
> 
>> Flattened attribute queries are incorrectly generated
>> -----------------------------------------------------
>> 
>>                Key: CAY-1484
>>                URL: https://issues.apache.org/jira/browse/CAY-1484
>>            Project: Cayenne
>>         Issue Type: Bug
>>         Components: Core Library
>>   Affects Versions: 3.0.1
>>        Environment: Gentoo linux
>> MySQL 5.1
>> java version "1.6.0_20"
>> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
>> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>>           Reporter: Misha Doronin
>>        Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CAY-1484.-Fixed-using-of-incorrect-alias.patch, CayenneBugDemo.zip
>> 
>>  Original Estimate: 1h
>> Remaining Estimate: 1h
>> 
>> Attached eclipse project demonstrating issue, including cayenne model
>> When creating database structure like:
>> table1
>>  t1key
>>  t1value
>>  t2keyref
>> table2
>>  t2key
>>  t2value
>>  t3keyref
>> table3
>>  t3key
>>  t3value
>> and cayenne model with flattened attribute table3.t3value in table2
>> it produces incorrect join query to table2 and 3:
>> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
>> Note t1.t2key, which obviously shouldn't be there and produces error.
> 
> -- 
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
> 
> 


[jira] Updated: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Ksenia Khailenko (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ksenia Khailenko updated CAY-1484:
----------------------------------

    Attachment: CAY-1484.-Fixed-using-of-incorrect-alias.patch

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CAY-1484.-Fixed-using-of-incorrect-alias.patch, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1484) Flattened attribute queries are incorrectly generated

Posted by "Ksenia Khailenko (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914783#action_12914783 ] 

Ksenia Khailenko commented on CAY-1484:
---------------------------------------

Thanks for the recent attachments, I'll see what it can be 

> Flattened attribute queries are incorrectly generated
> -----------------------------------------------------
>
>                 Key: CAY-1484
>                 URL: https://issues.apache.org/jira/browse/CAY-1484
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Gentoo linux
> MySQL 5.1
> java version "1.6.0_20"
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
>            Reporter: Misha Doronin
>         Attachments: bugdemo_maven_derby.zip, bugdemo_maven_derby_nobug.zip, CayenneBugDemo.zip
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Attached eclipse project demonstrating issue, including cayenne model
> When creating database structure like:
> table1
>   t1key
>   t1value
>   t2keyref
> table2
>   t2key
>   t2value
>   t3keyref
> table3
>   t3key
>   t3value
> and cayenne model with flattened attribute table3.t3value in table2
> it produces incorrect join query to table2 and 3:
> SELECT t1.t3value, t1.t2key, t0.t2value, t0.t3keyref, t0.t2key FROM testschema.table2 t0 JOIN testschema.table3 t1 ON (t0.t3key = t1.t3keyref) WHERE t0.t2key = ?
> Note t1.t2key, which obviously shouldn't be there and produces error.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.