Saturday, February 7, 2009

GORM executeQuery nuance

As far as You know executeQuery method allows the execution of HQL queries against a domain class. In previous post I mentioned issue concerning it in Grails. To recall I will list the latest query using Groovy shortcuts once more:
DocumentRevision.executeQuery("select max(dr.versionNumber) from ${DocumentRevision.name} dr")
Now I want to mention one nuance more. In my query I suppose that result type would be a numeric cause versionNumber property is Long type. But result type of using executeQuery method is always java.util.ArrayList. So even if You try to retrieve maximal value of some field, or count of some records the result type will always be ArrayList. Pay attention to that fact.

If You are not satisfied with such behavior of executeQuery method please refer to createCriteria method.

No comments:

Post a Comment