views:

38

answers:

1

Suppose I have the following Domain class:

class Book {
  String title
  String author
  byte[] largeCoverArtImage
}

I have a list view where I do not need to display largeCoverArtImage, how can I perform the following SQL query using GORM Criteria?

select title, author from Book
+3  A: 

You can run HQL queries that select individual columns with executeQuery:

def titlesAndAuthors = Book.executeQuery('select title, author from Book')

This will return a List of Object[], e.g.

for (row in titlesAndAuthors) {
   String title = row[0]
   String author = row[1]
   ...
}
Burt Beckwith
Not the answer I was hoping for, since I can't use the standard Criteria pagination pattern with executeQuery. But marked as accepted answer (i.e. "No"). I will point out that a solution that does work with Critiera, is to create a db View and separate Domain class (assuming legacy db) specifically for the list page (thereby easily leveraging the Criteria pagination pattern). Of course, the downside is that then you have two incompatible classes representing essentially the same set of records.
Stephen Swensen