【问题标题】:Hibernate Criteria and DetachedCriteria concate Properties or fieldsHibernate Criteria 和 DetachedCriteria 连接属性或字段
【发布时间】: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


    【解决方案1】:

    是的,我们可以在休眠时联系多个列运行时间。 我心爱的查询中有 concat 列。

     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();
    

    【讨论】:

    • 我正在使用 Criteria API... 这可能使用 Criteria API
    猜你喜欢
    • 1970-01-01
    • 2012-04-09
    • 2011-02-05
    • 2011-01-16
    • 2017-08-14
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多