Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve emebedded or component using Hibernate Criteria api

I have this class mapped as a entity, lets call it Person. Person has an embedded/component relation to Address. I am having trouble using a Criteria that would return Address objects. I have tried this:

Criteria.createCriteria(Address.class)

Which does not work. I guess I need to go through the entity but then I would need some kind of projection?

Criteria.createCriteria(Person.class).<<what goes here???>>

Suggestions?

like image 245
Konstantin Avatar asked Sep 24 '09 14:09

Konstantin


1 Answers

Component's lifetime is controlled by its owner; they are NOT considered associations. You therefore cannot retrieve component by itself from a query. You can, however, use it in criteria.

Assuming your "Address" class is mapped as "address" within "Person", you could do something like:

Criteria.createCriteria(Person.class)
 .add(Restrictions.eq("address.street", street));
like image 159
ChssPly76 Avatar answered Dec 04 '22 06:12

ChssPly76