2017-03-03 5 views
-3

나는 grails을 처음 사용하고 온라인 설명서를 통해 학습 할 수 있습니다.GORM (find function grails)과 함께 HQL을 사용하여 select를 사용하는 방법은 무엇입니까?

find() 기능을 읽는 중 나를 혼란스럽게 한 것이 있습니다.

Book.find(String query) // pass the HQL, However there are various overloaded variants. 

이제이 find() 기능을 사용하면됩니다.

Category.find("from Category as cat where cat.id = ? ", [5L]) //result is fine. 

내 범주 클래스

class Category { 

    String title; 
    String description 
    String image 
    static constraints = { 
     title blank: false, nullable: false 
     description blank: true, nullable: true 
    } 
} 

그러나 나는이 예외를 발생

Category.find("select cat.description from Category as cat where cat.id = ? ", [5L]) 
//or this query. 
Category.find("select description from Category as cat where cat.id = ? ", [5L]) 

이 HQL 쿼리 시도하는 경우 : -

Invalid query [select cat.description from Category as cat where cat.id = ? ] for domain class [class com.ecommerce.domain.Category]. Stacktrace follows: 
Message: Invalid query [select cat.description from Category as cat where cat.id = ? ] for domain class [class com.ecommerce.domain.Category] 

내 HQL에 문제가 있으시면 .....

또는 find(String query)으로 select 문을 사용하는 방법에 대한 답변을 보내주십시오.

은 하나의 결과를 들어 당신

+0

당신이'findall은()'시도? –

답변

1

감사합니다

Category.find("from Category cat where cat.id = ?", [5L])?.description 

또는 배수를위한

가 :

Category.find("from Category cat where cat.id = ?", [5L]).collect{ it.description } 
+0

그러나 ... 이것은 내가 예상했던대로 대답이 아니었다. 그러나이 대답은 하나의 투표를받을 가치가있다 ... –