(Quick Reference)

load

Purpose

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

Examples

// 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