Skip Headers

# Expressions for One-to-One and Aggregate Object Relationships

Previous

Next

Expressions can include an attribute that has a one-to-one relationship with another persistent class. A one-to-one relationship translates naturally into a SQL join that returns a single row.

Example: Using an Expression with a One-to-One Relationship illustrates a code fragment that accesses fields from an employee's address.

Using an Expression with a One-to-One Relationship

    emp.get("address").get("country").like("S%")

Example: Using an Expression with a One-to-One Relationship corresponds to joining the EMPLOYEE table to the ADDRESS table, based on the `address` foreign key, and checking for the country name.

You can nest these relationships infinitely, so it is possible to ask for complex information as follows:

    project.get("teamLeader").get("manager").get("manager").get("address").get("street")