Criteria condition or rewrite to HQL

View: New views
3 Messages — Rating Filter:   Alert me  

Criteria condition or rewrite to HQL

by ales@mincol.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
please help me. In my application I have a couple of criteria expressions something like:

def c = MyEntity.createCriteria()
def r = c {
    eq('enabled', Boolean.valueOf(params.enabled))
}


This works fine. But I need to add additional condition:

def c = MyEntity.createCriteria()
def r = c {
    eq('enabled', Boolean.valueOf(params.enabled))
    eq('someEntity.anotherEntity', AnotherEntity.findAll()[0])
}

This fails with could not resolve property: someEntity.anotherEntity of: MyEntity. Is there some way how to write condition someEntity.anotherEntity == AnotherEntity with criteria? Or I must rewrite crtieria expressions to HQL?

Best regards,

Ales
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Re: Criteria condition or rewrite to HQL

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

def r = c {
   eq('enabled', Boolean.valueOf(params.enabled))
   someEntity {
     eq('anotherEntity', otherEntity)
   }
}

You can sort using path expressions via GORM Labs.  I haven't implemented comparison calls with path
expressions, though.

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Grails Expert Retainer Services
http://smokejumperit.com/grails-retainer/


ales wrote:

> Hi all,
> please help me. In my application I have a couple of criteria
> expressions something like:
>
> /def c = MyEntity.createCriteria()
> def r = c {
>     eq('enabled', Boolean.valueOf(params.enabled))
> }/
>
> This works fine. But I need to add additional condition:
>
> /def c = MyEntity.createCriteria()
> def r = c {
>     eq('enabled', Boolean.valueOf(params.enabled))
>     *eq('someEntity.anotherEntity', AnotherEntity.findAll()[0])*
> }
> /
> This fails with *could not resolve property: someEntity.anotherEntity
> of: MyEntity*. Is there some way how to write condition
> *someEntity.anotherEntity == AnotherEntity* with criteria? Or I must
> rewrite crtieria expressions to HQL?
>
> Best regards,
>
> Ales
> --------------------------------------------------------------------- To
> unsubscribe from this list, please visit:
> http://xircles.codehaus.org/manage_email

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Criteria condition or rewrite to HQL

by ales@mincol.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It works! Thank you very much Robert.

Ales

Robert Fischer  wrote / napísal(a):

> def r = c {
>   eq('enabled', Boolean.valueOf(params.enabled))
>   someEntity {
>     eq('anotherEntity', otherEntity)
>   }
> }
>
> You can sort using path expressions via GORM Labs.  I haven't
> implemented comparison calls with path expressions, though.
>
> ~~ Robert Fischer, Smokejumper IT Consulting.
> Enfranchised Mind Blog http://EnfranchisedMind.com/blog
>
> Grails Expert Retainer Services
> http://smokejumperit.com/grails-retainer/
>
>
> ales wrote:
>> Hi all,
>> please help me. In my application I have a couple of criteria
>> expressions something like:
>>
>> /def c = MyEntity.createCriteria()
>> def r = c {
>>     eq('enabled', Boolean.valueOf(params.enabled))
>> }/
>>
>> This works fine. But I need to add additional condition:
>>
>> /def c = MyEntity.createCriteria()
>> def r = c {
>>     eq('enabled', Boolean.valueOf(params.enabled))
>>     *eq('someEntity.anotherEntity', AnotherEntity.findAll()[0])*
>> }
>> /
>> This fails with *could not resolve property: someEntity.anotherEntity
>> of: MyEntity*. Is there some way how to write condition
>> *someEntity.anotherEntity == AnotherEntity* with criteria? Or I must
>> rewrite crtieria expressions to HQL?
>>
>> Best regards,
>>
>> Ales
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>> http://xircles.codehaus.org/manage_email
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
>
>
> __________ Informacia od ESET NOD32 Antivirus, verzia databazy 4583
> (20091108) __________
>
> Tuto spravu preveril ESET NOD32 Antivirus.
>
> http://www.eset.sk
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email