Grails query (HQL) problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Grails query (HQL) problem

jnlltd
Hi everyone please help.

I have issue with HQL query Grails 2.4.3:

Now this query works perfectly

def home = {
def city = City.findByName("London")
        def services = Services.findByName("Shop")
def pages= Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}


This query as it is show below worked then for no reason stopped  no error message the json result is empty []

def search = {
def city = City.findByName(params.id)
        def services = Services.findByName(params.is)
def pages = Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}

Note: this the url value i am passing: http://localhost:8080/com.api.test/Pages/search/London?Shop

any ideas?  or how can I do this query and what will be the url?



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/5e49caa6-ba65-4fc2-9a01-057df7533016%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails query (HQL) problem

JohnTheBeloved
Firstly, I think you can assign the parameters local method variables before using them

Also, Have you tried to log the variables and check thier values

Your URL also seem strange, can you explain the different segments


On Thursday, 16 October 2014 11:19:24 UTC+1, jnlltd wrote:
Hi everyone please help.

I have issue with HQL query Grails 2.4.3:

Now this query works perfectly

def home = {
def city = City.findByName("London")
        def services = Services.findByName("Shop")
def pages= Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}


This query as it is show below worked then for no reason stopped  no error message the json result is empty []

def search = {
def city = City.findByName(<a href="http://params.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;">params.id)
        def services = Services.findByName(<a href="http://params.is" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;">params.is)
def pages = Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}

Note: this the url value i am passing: <a href="http://localhost:8080/com.api.test/Pages/search/London?Shop" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;">http://localhost:8080/com.api.test/Pages/search/London?Shop

any ideas?  or how can I do this query and what will be the url?



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/8db9eb7a-0d2f-4f52-b2e4-e487082912ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails query (HQL) problem

Jeff Scott Brown-3
In reply to this post by jnlltd


On October 16, 2014 at 3:19:26 AM, jnlltd ([hidden email]) wrote:

> def pages= Pages.findAll("from Pages as p where p.city= ? and p.services=
> ?" ,[city]+[services])

I don’t think this is related to your problem but do you know if there is a reason to construct to Lists and add them to each other there, as opposed to only creating 1 List?



JSB
--  
Jeff Scott Brown  
[hidden email]

Find The Cause ~ Find The Cure  
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.54416497.6b8b4567.eaa7%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails query (HQL) problem

jnlltd
In reply to this post by JohnTheBeloved

Country class

City Class

Services Class 

class Pages {

       String name

       String address

       String postcode

       String description

       Long phone

       String email

       String website

             

       static belongsTo = [country: Country, city: City, services: Services]

----------------------------------------------------------------------------------

Test 1 ) Controller;

def search = {      

       def city = City.findByName(“london”)

       def services = Services.findByName(“petshap”)

def results= Pages.findAll("from Pages as p where p.city = ? and p.services = ?" ,[city, services])

               render results as JSON          

       }     

POST Via AJAX; url posted is: http://localhost:8080/com.api.test/Pages/search/

The above example works OK (result [{"class":"com.api.test.Pages","id":2," etc…

 

------------------------------------------------------------------------------------

Test 2 ) Make a change to Controller;

def search = {      

       def city = City.findByName(params.id)

       def services = Services.findByName(“bus36”)

def results= Pages.findAll("from Pages as p where p.city = ? and p.services = ?" ,[city, services])

               render results as JSON          

       }     

POST Via AJAX; url posted is: http://localhost:8080/com.api.test/Pages/search/London

The above example works OK (result [{"class":"com.api.test.Pages","id":2," etc…

 

----------------------------------------------------------------------------------

Now this is what I want to do:

Test 3 ) Make a change to Controller;

def search = {      

       def city = City.findByName(params.id)

       def services = Services.findByName(params.id)

def results= Pages.findAll("from Pages as p where p.city = ? and p.services = ?" ,[city, services])

               render results as JSON          

       }     

POST Via AJAX; url posted is: http://localhost:8080/com.api.test/Pages/search/London?Bus36

(Result [] empty

Please let me know if use of ‘?’ to separate the params value is correct? (London?Bus36) I tried ‘,’ or ‘+’ or ‘&’ and they all return [].

How would you pass the to two query params in url? So I can make the AJAX to POST that pattern


On Friday, October 17, 2014 3:03:38 PM UTC+7, John Alade wrote:
Firstly, I think you can assign the parameters local method variables before using them

Also, Have you tried to log the variables and check thier values

Your URL also seem strange, can you explain the different segments


On Thursday, 16 October 2014 11:19:24 UTC+1, jnlltd wrote:
Hi everyone please help.

I have issue with HQL query Grails 2.4.3:

Now this query works perfectly

def home = {
def city = City.findByName("London")
        def services = Services.findByName("Shop")
def pages= Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}


This query as it is show below worked then for no reason stopped  no error message the json result is empty []

def search = {
def city = City.findByName(<a href="http://params.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;">params.id)
        def services = Services.findByName(<a href="http://params.is" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;">params.is)
def pages = Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}

Note: this the url value i am passing: <a href="http://localhost:8080/com.api.test/Pages/search/London?Shop" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;">http://localhost:8080/com.api.test/Pages/search/London?Shop

any ideas?  or how can I do this query and what will be the url?



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/6c56a2f5-359d-44e2-ae01-5a97666d5d31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails query (HQL) problem

micke_
In reply to this post by jnlltd
Hi

At a first glance it looks a bit strange that you are finding the City and Services domain objects using the same name value "params.id" , in your working hardcoded examples the values are always different.
If the names are different that explains why the query doesn't find a match.

I would make sure that the params.id attribute has the value you expect, perhaps you need to pass in two different request parameters which holds the City and Services names you want to find?

Cheers,
 Micke

On Thursday, 16 October 2014 11:19:24 UTC+1, jnlltd wrote:
Hi everyone please help.

I have issue with HQL query Grails 2.4.3:

Now this query works perfectly

def home = {
def city = City.findByName("London")
        def services = Services.findByName("Shop")
def pages= Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}


This query as it is show below worked then for no reason stopped  no error message the json result is empty []

def search = {
def city = City.findByName(<a href="http://params.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;">params.id)
        def services = Services.findByName(<a href="http://params.is" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;">params.is)
def pages = Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}

Note: this the url value i am passing: <a href="http://localhost:8080/com.api.test/Pages/search/London?Shop" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;">http://localhost:8080/com.api.test/Pages/search/London?Shop

any ideas?  or how can I do this query and what will be the url?



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/94f3b67b-d1b7-49eb-97ed-114601fd5ed1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grails query (HQL) problem

jnlltd
You correct about the params.id. 
I am new to grails I started to learn grails about 2 months ago so I was bit lost and too much to take in.  I found the solution when I started to look into URL mapping by modifying url mapping to allow parameter under different name the same query worked.  Params.id & params.id1.  But the strange thing was the query worked for two days without any modification url mapping. Well I have solved the problem gained some new knowledge.

 

On Sunday, October 26, 2014 5:12:22 PM UTC+7, Mikael Andersson wrote:
Hi

At a first glance it looks a bit strange that you are finding the City and Services domain objects using the same name value "<a href="http://params.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;">params.id" , in your working hardcoded examples the values are always different.
If the names are different that explains why the query doesn't find a match.

I would make sure that the <a href="http://params.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;">params.id attribute has the value you expect, perhaps you need to pass in two different request parameters which holds the City and Services names you want to find?

Cheers,
 Micke

On Thursday, 16 October 2014 11:19:24 UTC+1, jnlltd wrote:
Hi everyone please help.

I have issue with HQL query Grails 2.4.3:

Now this query works perfectly

def home = {
def city = City.findByName("London")
        def services = Services.findByName("Shop")
def pages= Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}


This query as it is show below worked then for no reason stopped  no error message the json result is empty []

def search = {
def city = City.findByName(<a href="http://params.id" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.id\46sa\75D\46sntz\0751\46usg\75AFQjCNE9pYT7y6HQ_CPjFF-biETLNyAswg';return true;">params.id)
        def services = Services.findByName(<a href="http://params.is" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fparams.is\46sa\75D\46sntz\0751\46usg\75AFQjCNGca0pL-Bs-ltmd9JJ9TAA8J1ArfA';return true;">params.is)
def pages = Pages.findAll("from Pages as p where p.city= ? and p.services= ?" ,[city]+[services])
render pages as JSON
}

Note: this the url value i am passing: <a href="http://localhost:8080/com.api.test/Pages/search/London?Shop" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Fcom.api.test%2FPages%2Fsearch%2FLondon%3FShop\46sa\75D\46sntz\0751\46usg\75AFQjCNH8om6KOXNIRAzq1MxO_6_VPkOWXA';return true;">http://localhost:8080/com.api.test/Pages/search/London?Shop

any ideas?  or how can I do this query and what will be the url?



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/bc0ad99b-df25-41ef-b444-2518d866fcb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.