gaffcz
gaffcz

Reputation: 3479

hibernate - definition of relationships - why?

What's the point or advantages of joining tables using hibernate, such as:

if there are relationships defined on the database level?

Upvotes: 1

Views: 72

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

There are two main advantages:

Being able to navigate between persistent objects:

order.getProduct().getSupplier().getCompany().getAddress().getStreet();

Being able to use joins in HQL (or Criteria) queries:

select address.street from Order order 
inner join order.product product
inner join product.supplier supplier
inner join supplier.company company
inner join company.address address
where order.id = :id

In fact, I would say associations is what makes an ORM an ORM. Without them you would only get basic objects, not linked to any other objects, and using JDBC would be enough.

Upvotes: 1

Related Questions