使用Hibernate Criteria API检索嵌入式或组件 [英] Retrieve emebedded or component using Hibernate Criteria api
问题描述
我把这个类映射为一个实体,我们称它为Person。 Person与Address有嵌入式/组件关系。我无法使用将返回地址对象的条件。
我试过这个:
$ p $ Criteria.createCriteria(Address.class)
哪个不行。我想我需要通过实体,但是我需要某种投影?
Criteria.createCriteria(Person.class )。<<这里是什么???>>
建议?
组件的生命周期由其所有者控制;他们不被视为协会。因此,您无法从查询中自行检索组件。您可以在标准中使用它。
假设您的Address类在Person中映射为address,您可以执行下列操作: p>
Criteria.createCriteria(Person.class)
.add(Restrictions.eq(address.street,street)) ;
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?
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));
这篇关于使用Hibernate Criteria API检索嵌入式或组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!