在休眠标准中达到3级标准 [英] go up to 3 level dephth in hibernate criterion

查看:92
本文介绍了在休眠标准中达到3级标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用休眠标准来获取结果。在这里,我提供了持久化类的演示设计。

  A类{
private B b;
}
B类{
private C c;
}
类别C {
private Long val;



$ b $ p
$ b

假设这些是hibernate持久性类,我不写所有映射注释数据库。

现在我的问题是我想根据 C类的val属性的值检索 A类的结果 strong>。



我尝试使用它获取它,

  Criteria c = Restrictions.eq(bcval,value); 
列表l = c.list;

它显示无法解析属性。我搜索了一下,并且知道标准不会达到这个深度。我不想转移到HQL。任何想法??

解决方案

  Criteria c = session.createCriteria(A.class)
.createCriteria(b)
.createCriteria(c)
.add(Restrictions.eq(val,value));

列表l = c.list;


i am using hibernate criterion for fetching results. Here with i provided demo design of my persistence class.

Class A{
private B b;
}
Class B{
private C c;
}
Class C{
private Long val;
}

assume these are the hibernate persistence classes i am not writing all annotations of mapping with database.

now my problem is i want to retrieve results of Class A according to the value of Class C's val property.

i tried to fetch it using,

Criteria c = Restrictions.eq("b.c.val", value);
List l = c.list;

it shows could not resolve property. i searched and came to know criteria wont work up to this much depth. i don't want shift to HQL. any idea??

解决方案

Criteria c = session.createCriteria(A.class)
    .createCriteria("b")
    .createCriteria("c")
    .add(Restrictions.eq("val", value));

List l = c.list;

这篇关于在休眠标准中达到3级标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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