使用Hibernate Criteria API检索嵌入式或组件 [英] Retrieve emebedded or component using Hibernate Criteria api

查看:90
本文介绍了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆