2012-12-17 40 views
1

是否存在與以下HQL等價的任何hibernate標準查詢?相當於HQL的Hibernate標準

「選擇新的TestTable的(t.id,t.param1,t.param2,t.param3)FROM TestTable的T」

回答

1

在要加載表的一些列的情況下,你可能需要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(); 
+0

:Acutally我的問題是關於[這](http://stackoverflow.com/questions/2801764/hibernate-criteria-api-equivalent-to-hql-select-clause),我從[這裏]得到了答案(http ://stackoverflow.com/questions/2801764/hibernate-criteria-api-equivalent-to-hql-select-clause)和[這裏](http://stackoverflow.com/questions/3958222/using-hibernate-criteria-至選擇 - 到 - 值的對象)。感謝您的評論。 – Deepesh

0

如果你正在嘗試做的是查詢TestTable的的行,並得到TestTable的休眠對象,只需在您嘗試檢索的Hibernate對象的類上創建一個Criteria對象。

Criteria crit = sess.createCriteria(TestTable.class); 
List results = crit.list(); 
+0

NOTE:事實上,我的問題是關於[這](http://stackoverflow.com/questions/2801764/ hibernate-criteria-api-equivalent-to-hql-select-clause),我從[這裏]得到了答案(http://stackoverflow.com/questions/2801764/hibernate-criteria-api-equivalent-to-hql-選擇子句)和[這裏](http://stackoverflow.com/questions/3958222/using-hibernate-criteria-to-select-into-value-objects)。感謝您的評論。 – Deepesh