Would you please let me know how you can perform a projection on the Grails domain class?! During my situation, I wish to get a listing of (for instance) User's title by their Ids. This means during my method, I pass a listing of userId and obtain a listing of user's names. Does dynamic techniques of Groovy domain support this feature? At the moment, I am using my below function:

public String getUserNamesByIds(String[] ids) 


    return names.toString()

As you can see, Among the finest to find the title (and make the entire string). I believe it isn't good because I must do many small steps, and perform many queries to database to find the User object. Can there be much better method to get this done? Many thanks!

Use a Criteria with forecasts to find the names from the customers given its IDs, doing something similar to:

public List getUserNamesByIds(String[] ids) forecasts title")


       'in'("id", ids)


You'll be able to convert their email list of user names in to the a String by doing:

List customers = getUserNamesByIds(...)

String concatenatedNames = (customers ? customers.join(",") : "")

Read much more about criterias and forecasts within the Grails user guide.

This is a terrible idea. This is because every call to User.get(id) constitutes a call within the wire over the network. This is costly, and even when your database responds in 20 ms doing 1000 of these normally takes 20 seconds--a significant very long time for the user to hold back. A much better idea is to buy the group of customers you are looking at by some kind of query then iterate them over while they're in memory. That takes 1 ns or less for every loop invocation.

This implementation generally is among the biggest reasons web applications are slow...