在休眠中,有一种方法可以检索按多对一关系对象的属性排序的实体列表
我有一个多对一关系,如下所示
<hibernate-mapping default-lazy="false" package="com.my.sample.data">
<class name="Person" table="person_table">
<!-- other stuff -->
<many-to-one class="Company" column="p_id" fetch="join" insert="false" name="company" update="false" not-found="ignore" not-null="false" />
公司映射到company_table并具有属性company_id。有没有办法通过 hibernate 获取按 Company.company_id 排序的人员列表。因此,当我查询
items = (List<A>) getSession().createCriteria(Person.class)
.add(Restrictions.in("person_id", pIds)
).list();
So 时,我最终得到了按 company_id 排序的人员列表。 我发现的唯一 addOrder 语法采用了一个属性名称,就像
addOrder(Order.asc("person_id").`
我找不到如何引用类似于
addOrder.Order.asc("company.company_id")
“谢谢”的外部对象的属性名称一样。
I have a many-to-one relationship as follows
<hibernate-mapping default-lazy="false" package="com.my.sample.data">
<class name="Person" table="person_table">
<!-- other stuff -->
<many-to-one class="Company" column="p_id" fetch="join" insert="false" name="company" update="false" not-found="ignore" not-null="false" />
Company maps to company_table and has a property company_id. Is there a way to fetch a list of Person ordered by Company.company_id via hibernate. So when I query
items = (List<A>) getSession().createCriteria(Person.class)
.add(Restrictions.in("person_id", pIds)
).list();
So I end up with a list of Person ordered by company_id.
The only addOrder syntax I found took a property name like
addOrder(Order.asc("person_id").`
I could not find how to refer to a property name of a foreign object something akin to
addOrder.Order.asc("company.company_id")
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。我认为这会有所帮助。基于标准理论。 Criteria 不能进行隐式连接。所以我们将其明确化。
示例:
希望这对您有用。
Try this. I think this will help. Base on the Criteria theory. Criteria cannot do implicit join. so we make it explicit.
Example:
Hope this useful for you.