DetachedCriteria关联有两种方式
1. DetachedCriteria dc = DetachedCriteria.forClass(EmailPushRecord.class);
dc.setFetchMode("user", FetchMode.JOIN); dc.setFetchMode("emailTemplate", FetchMode.JOIN);dc.createAlias("user", "user");
dc.createAlias("emailTemplate", "emailTemplate");到了这一步下面就可以直接用
dc.add(Restrictions.or(
Restrictions.like("user.name", messageReturn.getTitle(),MatchMode.ANYWHERE), Restrictions.like("emailTemplate.name", messageReturn.getTitle(),MatchMode.ANYWHERE), Restrictions.like("emailTemplate.title", messageReturn.getTitle(), MatchMode.ANYWHERE))
);
2.Disjunction disjunction = Restrictions.disjunction();
DetachedCriteria dc = dc.createAlias("user", "user", CriteriaSpecification.LEFT_JOIN).createAlias("emailTemplate", "emailTemplate",CriteriaSpecification.LEFT_JOIN);disjunction.add(Restrictions.or(
Restrictions.like("user.name", messageReturn.getTitle(),MatchMode.ANYWHERE), Restrictions.like("emailTemplate.name", messageReturn.getTitle(),MatchMode.ANYWHERE), Restrictions.like("emailTemplate.title", messageReturn.getTitle(), MatchMode.ANYWHERE))
);