getAll is an extended version of get that accepts multiple identifiers and returns List instances. The size of the list will be the same as the number of identifiers provided; any misses will result in null in this slot. See http://grails.org/doc/latest/ref/Domain%20Classes/getAll.html
findAll allows you to use HQL queries and supports pagination, but they are not limited to instances of the calling class, so I use executeQuery . See http://grails.org/doc/latest/ref/Domain%20Classes/findAll.html
List finds all instances and supports pagination. See http://grails.org/doc/latest/ref/Domain%20Classes/list.html
get retrieves one instance by id. It uses the instance cache, so multiple calls in the same Hibernate session will result in no more than one database call (for example, if the instance is in the second level cache and you enable it).
findById is a dynamic crawler like findByName , findByFoo , etc. In fact, it does not use the instance cache, but can be cached if query caching is enabled (as a rule, this is not a good idea). get should be preferred since its caching is much smarter; cached query results (even for one instance like this) are pessimistic cleared more often than you expected, but the instance cache should not be so pessimistic.
In one case, which I would use for findById , as a security check, combined with another property. For example, instead of retrieving an instance of CreditCard using CreditCard.get(cardId) , I would find the user who is currently logged in and use CreditCard.findByIdAndUser(cardId, user) . This assumes that CreditCard has a User user property. Thus, both properties must match, and this would block the hacker from accessing the card instance, since the card ID could match, but the user did not.
Burt Beckwith Jan 18 '12 at 19:53 2012-01-18 19:53
source share