Difference between findAll, getAll and list in Grails

getAll is an enhanced version of get that takes multiple ids and returns a List of instances. The list size will be the same as the number of provided ids; any misses will result in a null at that slot. See http://grails.org/doc/latest/ref/Domain%20Classes/getAll.html findAll lets you use HQL queries and supports pagination, but they’re not limited … Read more

Grails domain class: unique constraint for multiple columns

userName(unique: [‘countryId’]) You can include as many other properties in the array that make up the other properties that must be considered in the “unique” constraint on the username. So, for example if you wanted to make userName unique within a countryId and provinceId it would look like this: userName(unique: [‘countryId’, ‘provinceId’]

How can I return a 404/50x status code from a Grails Controller?

Setting the response status with its own statement is good enough. It doesn’t look too ugly and is pretty straightforward: response.status = 404; I’ve used this successfully myself and have seen others do it this way too. Since it’s just a setter, you can also do other stuff after setting the status. Whichever status you … Read more

Grails BuildConfig.groovy, difference between build, compile, and runtime?

build – dependency that is only needed by the build process runtime – dependency that is needed to run the application, but not compile it e.g. JDBC implementation for specific database vendor. This would not typically be needed at compile-time because code depends only the JDBC API, rather than a specific implementation thereof compile – … Read more

How to access Grails configuration in Grails 2.0?

If you need it in an artifact that supports dependency injection, simply inject grailsApplication class MyController { def grailsApplication def myAction = { def bar = grailsApplication.config.my.property } } If you need it in a bean in, say, src/groovy or src/java, wire it up using conf/spring/resources.groovy // src/groovy/com/example/MyBean.groovy class MyBean { def grailsApplication def foo() … Read more

How to change grails localhost port?

This solution adds to the answers http://stackoverflow.com/a/10956283/122457. In Grails 2.x, add the following to BuildConfig.groovy: grails.server.port.http = 8090 See http://forum.springsource.org/archive/index.php/t-97024.html for further details.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)