Reputation: 61
I have a strange bug with Grails. I want to get back some persisted datas, so I execute a HQL query for it. I need to retrieve a list from a domain class, which has a manyToOne relation.
The query is pretty basic, look by yourself :
def listActuel = PositionnementProfil.find("FROM PositionnementProfil as pp where pp.positionnement.libelle='actuel'")
But I get this error :
Error 500: Executing action [positionnement] of controller [package.ProfilController] caused exception: Invalid query [FROM PositionnementProfil as pp where pp.entreprise.libelle='Orange'] for domain class [class package.PositionnementProfil]
So in doubt, I've tried with a more basic query, just to get sure, and as I kept on having this kinf of error I decided to try with another class. Still got this marvelous message with this piece of code :
def test = Profil.find("FROM Profil as p where p.firstName like='Jean'")
//NOtice I executed more complex queries on this class with success, here not
Eevn though I'm new in grails I don't think I'm a noob (please God, tell me I did everything right :D ), I followed once again grails doco (http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.4.3%20Hibernate%20Query%20Language%20%28HQL%29), I cleaned my project by executing "grails clean", restarted my computer, and still got this nice problem. I don't know why, but it seems to have troubles only in this part of my code :
class ProfilController {
def scaffold = Profil
def positionnement = {
def test = Profil.find("from profil as p where p.firstName like 'Jean'")
}
//... I've put this code in other places, but I don't believe in "supernatural" places
}
I really din't see how to get out of this. Other symptom, Netbeans doesn't seen to recognize GORM autocompletion.
Upvotes: 0
Views: 333
Reputation: 75671
I think I remember a recent issue with case-sensitivity with find()
and findAll()
but that won't help you since the fix will be in 2.0. But the easy workaround is to use executeQuery()
instead since that's just a direct hook into Hibernate HQL:
def listActuel = PositionnementProfil.executeQuery(
"FROM PositionnementProfil as pp where pp.positionnement.libelle='actuel'")[0]
The only difference other than the method name is that since executeQuery()
returns a List
you need to take the 1st element with [0]
Upvotes: 1