org.codehaus.groovy.grails.orm.hibernate.metaclass
Class FindPersistentMethod

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.metaclass.AbstractStaticMethodInvocation
      extended by org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractStaticPersistentMethod
          extended by org.codehaus.groovy.grails.orm.hibernate.metaclass.FindPersistentMethod
All Implemented Interfaces:
org.codehaus.groovy.grails.commons.metaclass.StaticMethodInvocation, org.grails.datastore.gorm.finders.FinderMethod

public class FindPersistentMethod
extends AbstractStaticPersistentMethod

The "find" persistent static method allows searching for instances using either an example instance or an HQL query. This method returns the first result of the query. A GrailsQueryException is thrown if the query is not a valid query for the domain class.

Examples in Groovy: // retrieve the first account ordered by account number def a = Account.find("from Account as a order by a.number asc") // with query parameters def a = Account.find("from Account as a where a.number = ? and a.branch = ?", [38479, "London"]) // with query named parameters def a = Account.find("from Account as a where a.number = :number and a.branch = :branch", [number:38479, branch:"London"]) // query by example def a = new Account() a.number = 495749357 def a = Account.find(a)


Field Summary
 
Fields inherited from class org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractStaticPersistentMethod
application
 
Constructor Summary
FindPersistentMethod(org.hibernate.SessionFactory sessionFactory, java.lang.ClassLoader classLoader, org.codehaus.groovy.grails.commons.GrailsApplication application)
           
 
Method Summary
protected  java.lang.Object doInvokeInternal(java.lang.Class clazz, java.lang.String methodName, groovy.lang.Closure additionalCriteria, java.lang.Object[] arguments)
           
protected  java.lang.Object doInvokeInternal(java.lang.Class clazz, java.lang.String methodName, grails.gorm.DetachedCriteria additionalCriteria, java.lang.Object[] arguments)
           
 
Methods inherited from class org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractStaticPersistentMethod
getCriteria, getHibernateTemplate, invoke, invoke, invoke
 
Methods inherited from class org.codehaus.groovy.grails.commons.metaclass.AbstractStaticMethodInvocation
getPattern, isMethodMatch, setPattern, setPattern, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.grails.datastore.gorm.finders.FinderMethod
isMethodMatch, setPattern
 

Constructor Detail

FindPersistentMethod

public FindPersistentMethod(org.hibernate.SessionFactory sessionFactory,
                            java.lang.ClassLoader classLoader,
                            org.codehaus.groovy.grails.commons.GrailsApplication application)
Method Detail

doInvokeInternal

protected java.lang.Object doInvokeInternal(java.lang.Class clazz,
                                            java.lang.String methodName,
                                            grails.gorm.DetachedCriteria additionalCriteria,
                                            java.lang.Object[] arguments)
Specified by:
doInvokeInternal in class AbstractStaticPersistentMethod

doInvokeInternal

protected java.lang.Object doInvokeInternal(java.lang.Class clazz,
                                            java.lang.String methodName,
                                            groovy.lang.Closure additionalCriteria,
                                            java.lang.Object[] arguments)
Specified by:
doInvokeInternal in class AbstractStaticPersistentMethod