如何为下面的SQL查询编写hibernate条件查询

时间:2014-11-03 11:22:40

标签: java hibernate

SELECT (Title + ' ' & Forename & ' ' & Surname) AS FullName FROM details;

SELECT (Title || ' ' || Forename || ' ' || Surname) AS FullName FROM details;

我也想用 FullName的休眠投影

1 个答案:

答案 0 :(得分:0)

如果您想要条件库投影,可以使用ProjectionList

ProjectionList prjection = Projections.projectionList();
if(abc){
    prjection.add(Projections.property("firstname"));
}
else if(xyz){
    prjection.add(Projections.property("Surname"));
}

    ........

    criteria.setProjection(prjection);

如果你想在标准中使用OR / And Condition而不是你可以使用 Junction invitationTypeNotJunction = Restrictions.conjunction(); Junction invitationTypeJunction = Restrictions.disjunction();

您可以参考http://www.java2s.com/Tutorial/Java/0350__Hibernate/RestrictionsDisjunction.htm链接获取更多信息