我想知道是否可以将此标准转换为独立的标准。我无法正确理解分离标准。可以帮上忙。

Criteria crit = sessionC.createCriteria(OP_DOCTOR_VISIT.class, "OPDV1");
crit.createAlias("OPDV1.OP_VISIT", "OPDV2", JoinType.LEFT_OUTER_JOIN, Restrictions.and(Restrictions.eq("OPDV2.FORM", "NEW"), Restrictions.ge("OPDV2.USER_DATETIME", fromdate), Restrictions.le("OPDV2.USER_DATETIME", todate)));
    crit.add(Restrictions.ge("OPDV1.USER_DATETIME", fromdate));
    crit.add(Restrictions.le("OPDV1.USER_DATETIME", todate));
    ProjectionList p1 = Projections.projectionList();
    p1.add(Projections.alias(Projections.count("OPDV1.OP_VISIT_ID"), "TOTAL"));
    p1.add(Projections.count("OPDV2.FORM"));
    p1.add(Projections.alias(Projections.sqlGroupProjection("date(this_.USER_DATETIME) as createdDate", "createdDate", new String[]{"createdDate"}, new Type[]{StandardBasicTypes.DATE}), "DAT"));
    crit.setProjection(p1);


是否可以重写上面的内容,以便避免在下面给出的POJO中使用“ @OneToMany”。

POJO

@Entity
@Table(name = "OP_DOCTOR_VISIT")
@SQLDelete(sql = "UPDATE OP_DOCTOR_VISIT SET DELETED = 'DELETED' WHERE OP_VISIT_ID = ? and VERSION_UPDATES = ?")
@Where(clause = "DELETED <> 'DELETED'")
public class OP_DOCTOR_VISIT implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "OP_VISIT_ID")
private Long OP_VISIT_ID;

@OneToMany(mappedBy = "OP_VISIT_ID", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@LazyCollection(LazyCollectionOption.EXTRA)
@Fetch(FetchMode.SELECT)
private List<OP_DOCTOR_VISIT> OP_VISIT;

    public Long getOP_VISIT_ID() {
        return OP_VISIT_ID;
    }

    public void setOP_VISIT_ID(Long OP_VISIT_ID) {
        this.OP_VISIT_ID = OP_VISIT_ID;
    }

    public List<OP_DOCTOR_VISIT> getOP_VISIT() {
        return OP_VISIT;
    }

    public void setOP_VISIT(List<OP_DOCTOR_VISIT> OP_VISIT) {
        this.OP_VISIT = OP_VISIT;
    }

}

最佳答案

仅在创建条件对象的第一行。


DetachedCriteria允许您创建不带会话的查询。因此,在构建查询时不需要会话。 DetachedCriteria与条件相同,除了您可以创建不带会话的查询。

DetachedCriteria detachedCriteria = DetachedCriteria.forClass(OP_DOCTOR_VISIT.class);
最后,当您有一个会话对象可用时,您可以执行查询

`criteria .getExecutableCriteria(session)。

08-05 20:08