EntityLoadByPK()
Loads and returns the entity for the given primary key, or null if not found.
Requires Extension: Hibernate ORM Engine Extension
EntityLoadByPK( name=string, id=any, unique=boolean );
Returns: any
| Argument | Description |
|---|---|
|
name
string,
required
|
edit
Name of the entity to be loaded. |
|
id
any,
required
|
edit
The primary key value of the entity that must be loaded |
Unimplemented Argument(s)
| Argument | Description |
|---|---|
|
unique
boolean,
optional
|
edit
If unique is set to true, then the entity is returned. If you are sure that only one record exists that matches this filtercriteria, then you can specify unique=true, so that a single entity is returned instead of an array. If you set unique=true and multiple records are returned, then an exception occurs. * unimplemented * |
Usage Notes
editReturns null if no entity matches the given primary key — always check with isNull() before using the result.
For composite primary keys, pass a struct with the key property names and values.
The returned entity is persistent — it is tracked by the ORM session. Any modifications are automatically detected and persisted on flush.
See ORM - Querying for all entity loading options.
Examples
edit// Load by primary key
user = entityLoadByPK( "User", 42 );
if ( isNull( user ) )
throw( message="User not found" );
// Composite primary key
enrolment = entityLoadByPK( "Enrolment", { studentId: "abc", courseId: 101 } );
See also
- ORM
- ORM - Getting Started
- ORM - Querying
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)