【发布时间】:2014-02-07 15:44:43
【问题描述】:
我有一个criteria like
public ArrayList<Student>getStudentsWithPicture(final Student student)
{
final Criteria criteria = session.createCriteria(Student.class).add(and(prepareForSelect()));
criteria.add(Subqueries.gt(1L,getDetached);//the students with a less added picture...
return new ArrayList<Student>(criteria.list());
}
我需要 table Pictures 中图片较少的学生,但这个数据库是旧数据库
他们存储连接some fields for the student entity的图片
是的,很奇怪
我想要这样的东西
SQL
select
this_.ID as y0_,
this_.C01 as y1_,
this_.C02 as y2_,
this_.C03 as y3_
from
student_table this_
where
(
and this_.C11=true
and 1>=
(
select
count(*)
from
PICTURE_TABLE this_
where
(
this_.C03='concatening'+ this_.ID+ this_.C01+this_.C02+this_.C03//the fields of the student
)
)
)
这只是一个可以理解的例子,实际查询要糟糕得多...
如您所见,我想要 status='true' 的学生,他们在 PICTURE_TABLE 上的匹配项较少,但表中的字段 C03 是通过连接 @ 的字段创建的987654328@ 我也找回来了...
my detached
public DetachedCriteria getWithDetachedMatchStudentWithPictures()
{
final String concatedFields = ...........how i accomplish this??????.................
final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Pictures.class)
.add(equals("c03",concatedFields))
.setProjection(addProjection("id"))
.setResultTransformer(transformer(Pictures.class));
return detachedCriteria;
}
我的问题是。
我可以在运行时连接字段..?? using Criteria A.P.I
有什么办法吗?
非常感谢
【问题讨论】:
标签: java hibernate criteria detachedcriteria