【发布时间】:2016-08-11 08:19:05
【问题描述】:
我想获取具有不同批处理代码和 ID 的行。
以下代码现在正在获取重复的批处理代码,例如:
第 1 批 12,
批次1 45,
批次1 63,
批次2 96,
批次2 96
@Entity
@Table(name = "key")
public class Key implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, length = 11)
@Column(name = "batch_code", nullable = false)
private String batchCode;
//getter , setter
}
Criteria c = getSession().createCriteria(Key.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("batchCode"));
c.setProjection(Projections.distinct(projList));
c.setProjection(Projections.property("id"));
if (searchTerm != null && !searchTerm.isEmpty()) {
c.add(Restrictions.like("keyCode", searchTerm.toUpperCase() + "%"));
}
c.setFirstResult(currPosition);
c.setMaxResults(pageSize);
List<Key> result = c. list();
【问题讨论】:
标签: java hibernate hibernate-criteria