Within the world of GRAILs, GORM is your object manager. Think of this as Hibernate with some rather nice dynamic syntactic sugar. For the most part, it is fairly consistent and does what you want it to. However, I’ve recently ran into 2 weird issues with it.
For these issues lets assume we have 2 classes. One called Users, which has an email address and a name, and another called SuperUser, which inherits from Users but adds nothing new.
-
One of the dynamic functions is findOrSaveWhere. The method enables you to guarantee that a result is returned. If the conditions for the data item wasn’t found, then it will be created for you and saved. If you are attempting to do a Users.findOrSaveWhere and you don’t give it enough parameters to make a valid instance, or if you have invalid data, the object won’t be saved. This is ok, as that the returned object exists, but will tell you that it was invalid. However within Grails/GORM, you’re supposed to be able to get an exception if you enable the property failOnSave within the method (it is valid within the save method). Unfortunately, that is not a valid method in the findOrSaveWhere dynamic method. It turns out that this is an old issue that has been unaddressed.
-
This is an issue between a controller and it’s GSP view. If you are trying to list all of the users, in the example, the view won’t bind properly to the generated GSP view. The GSP View will assume that the variable for index will be UsersInstanceList. However, given the mixed types, the control returns some other type. (I’m not sure what this is). The solution to this is to explicitly define the list in the model. Here is the StackOverflow Reference.