Grails JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile
Grails
  • Grails
  • GRAILS-9432 Miscellaneous Where query problems
  • GRAILS-8256

DetachedCriteria's association query

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0-RC1
  • Fix Version/s: 2.2-RC2
  • Component/s: Persistence
  • Labels:
    None
  • Environment:
    Lion,JDK 6

Description

the original url: http://grails.1312388.n4.nabble.com/DetachedCriteria-s-association-query-td3989063.html

I have some domains which association reference are more than 2,for example:

Class A { 
    B b 
} 

Class B{ 
    C c 
} 

Class C { 
    String name 
} 

When i use the detachedCriteria like this:

new DetachedCriteria(A).build { 
    b { 
        c { 
                eq('name','test') 
        } 
    } 
} 

There will throw such exception:
message: could not resolve property: c of: A

>> 639 | doCall in grails.gorm.DetachedCriteria$_list_closure2

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    867 doCall in grails.gorm.DetachedCriteria$_withPopulatedQuery_closure9
    540 doCall . . . . . . . in org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure18
    301 execute in org.grails.datastore.mapping.core.DatastoreUtils
    34 execute . . . . . . in org.grails.datastore.gorm.AbstractDatastoreApi
    539 withDatastoreSession in org.grails.datastore.gorm.GormStaticApi
    850 withPopulatedQuery . in grails.gorm.DetachedCriteria

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Git Commits
Hide
Permalink
Eli Israel added a comment - 02/May/12 6:33 PM

I'm getting this same error in 2.0.3. Here's a routine that looks to me like it should work, but I get the same exception described above. "could not resolve property 'user' of 'StatusUpdate'"

The 'user' property belongs to the UpdateStream object references by the association "streams"

def Collection<StatusUpdate> getUpdates(String streamName, DetachedCriteria crit, Map params = [:]) {
crit = crit.build {
streams {
and {
eq 'name', streamName
user {
inList 'externalID', this.socialAccounts.collect

{ it.externalID }

}
}
}
}

crit.list(params)
}

Show
Eli Israel added a comment - 02/May/12 6:33 PM I'm getting this same error in 2.0.3. Here's a routine that looks to me like it should work, but I get the same exception described above. "could not resolve property 'user' of 'StatusUpdate'" The 'user' property belongs to the UpdateStream object references by the association "streams" def Collection<StatusUpdate> getUpdates(String streamName, DetachedCriteria crit, Map params = [:] ) { crit = crit.build { streams { and { eq 'name', streamName user { inList 'externalID', this.socialAccounts.collect { it.externalID } } } } } crit.list(params) }
Hide
Permalink
Eli Israel added a comment - 23/May/12 6:50 AM

Fix in 2.2? This seems like a major bug without a decent workaround. If the fix is moving from being in the next "hot fix" to something two minor releases out, can we see why? Is there a dependency? This seems puzzling.

Show
Eli Israel added a comment - 23/May/12 6:50 AM Fix in 2.2? This seems like a major bug without a decent workaround. If the fix is moving from being in the next "hot fix" to something two minor releases out, can we see why? Is there a dependency? This seems puzzling.
Hide
Permalink
Aaron Long added a comment - 18/Jul/12 11:50 AM

I believe this bug has a few other variations which are much worse. In the example given, if you try to use more than one nested association, it will fail outright. However, if you just reference one association and then provide criteria inside it using the eq() method, it will do the join and ignore the criteria, returning incorrect results.

Also, if you use the new Groovy-like syntax and try to reference more than one property deep, it will again create incorrect SQL and ignore the criteria. So, doing something like:

Person(name: String) -> Face(type: String) -> Nose

Nose.findAll {
    face.type == 'FAT' // this works
}

Nose.findAll {
    face.person.name == 'Jon' // this criteria is ignored
}

In the latter example, the join to Person never occurs and the query has a strange 1=1 at the end as if it had no criteria. I'm attaching a test app that includes a few of these examples as tests.

Show
Aaron Long added a comment - 18/Jul/12 11:50 AM I believe this bug has a few other variations which are much worse. In the example given, if you try to use more than one nested association, it will fail outright. However, if you just reference one association and then provide criteria inside it using the eq() method, it will do the join and ignore the criteria, returning incorrect results. Also, if you use the new Groovy-like syntax and try to reference more than one property deep, it will again create incorrect SQL and ignore the criteria. So, doing something like: Person(name: String ) -> Face(type: String ) -> Nose Nose.findAll { face.type == 'FAT' // this works } Nose.findAll { face.person.name == 'Jon' // this criteria is ignored } In the latter example, the join to Person never occurs and the query has a strange 1=1 at the end as if it had no criteria. I'm attaching a test app that includes a few of these examples as tests.
Hide
Permalink
Aaron Long added a comment - 18/Jul/12 1:42 PM

I actually consolidated all of my issues into one ticket and set of tests, GRAILS-9280.

Show
Aaron Long added a comment - 18/Jul/12 1:42 PM I actually consolidated all of my issues into one ticket and set of tests, GRAILS-9280 .
Hide
Permalink
sathish hariharan added a comment - 19/Oct/12 12:46 AM

Does anyone have a good workaround for this?

Show
sathish hariharan added a comment - 19/Oct/12 12:46 AM Does anyone have a good workaround for this?

People

  • Assignee:
    Graeme Rocher
    Reporter:
    Ford Guo
Vote (4)
Watch (5)

Dates

  • Created:
    04/Nov/11 2:37 AM
    Updated:
    24/Oct/12 2:56 AM
    Resolved:
    24/Oct/12 2:56 AM
    Last Reviewed:
    01/Jan/10

Agile

  • View on Board
  • Atlassian JIRA (v5.2.1#813-sha1:277a546)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Grails project. Try JIRA - bug tracking software for your team.