# EntityLoadByPK()

Loads and returns the entity for the given primary key, or null if not found.

**Requires Extension:** [Hibernate ORM Engine Extension](https://download.lucee.org/#FAD1E8CB-4F45-4184-86359145767C29DE)

```
EntityLoadByPK( name=string, id=any, unique=boolean );
```

**Returns:** any

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| name | string | Yes | Name of the entity to be loaded. |  |
| id | any | Yes | The primary key value of the entity that must be loaded |  |

# Usage Notes

Returns `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](../../recipes/orm-querying.md) for all entity loading options.

# Examples

```cfml
// 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 } );
```







# Categories

[ORM](../../categories/orm.md)

# See Also

[ORM - Getting Started](../../recipes/orm-getting-started.md), [ORM - Querying](../../recipes/orm-querying.md)