是否存在与以下 HQL 等效的休眠条件查询?
“从TestTable t中选择新的TestTable(t.id,t.param1,t.param2,t.param3)”
如果您想加载表格的某些列,您可能需要Projection
Criteria crit = getSession().createCriteria(TestTable.class, "t");
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("id"));
projectionList.add(Projections.property("param1"));
projectionList.add(Projections.property("param2"));
projectionList.add(Projections.property("param1"));
crit.setProjection(projectionList);
List results = crit.list();
如果您要做的只是查询 TestTable 的行并获取 TestTable hibernate 对象,只需在您尝试检索的 Hibernate 对象的类上创建一个 Criteria 对象。
Criteria crit = sess.createCriteria(TestTable.class);
List results = crit.list();