////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== load



=== Purpose


Returns a proxy instance of the domain class for the given identifier.


=== Examples


[source,groovy]
----
// load a single instance
def b = Book.load(1)
String title = b.title
...

// delete an instance without retrieving it
Book.load(1).delete()
----


=== Description


`load` usually returns a proxy for the instance which is initialized on-demand, when a method other than `getId()` is invoked. `load()` only returns `null` if the provided id is `null`, so you cannot use it to test for existence. If you provide an id for an instance that doesn't exist, a proxy will be returned and an exception will be thrown only when you call any instance method other than `getId()`.

If there is an existing instance with the same id in the Hibernate session or 2nd-level cache, load() will return that non-proxy instance instead of a proxy.

Parameters:

* `id` - The id of the object to retrieve
