gpt4 book ai didi

java - Hibernate Criteria 和 DetachedCriteria 连接属性或字段

转载 作者:行者123 更新时间:2023-12-01 13:29:54 24 4
gpt4 key购买 nike

我有一个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());
}

我需要表格图片中图片较少的学生,但该数据库是旧数据库

他们存储连接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该表中的内容是通过连接 Student 的字段创建的我也检索到了它...

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

有什么办法吗?

非常感谢

最佳答案

是的,我们可以在hibernate中运行时联系多个列。我在我心爱的查询中有连续列。

 Query query = session.createQuery("SELECT DISTINCT f.fileid , f.filename,  f.filetype , f.folderpath , max(f.version) from FileBean f  GROUP BY concat(folderpath,filename,'.',filetype)");
result = query.list();

关于java - Hibernate Criteria 和 DetachedCriteria 连接属性或字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21631979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com