标签:china test 英文 参数 calendar 策略 多个 where 微软
Hibernate 提供的HQL(Hibernate Query Language)语句也支持批量 update 和 delete 语法,语法格式如下:
[UPDATE | DELETE] FROM <ClassName> [WHERE conditions]
关于上面的语法格式有以下需要值得注意的:
? ?
要使用HQL查询,使用HQL查询按如下步骤进行:
? ?
代码片段如下:
public static void main(String[] args) {
Session curSession = hibernateUtils.openSession();
Transaction curTransaction = null;
Calendar calendar = Calendar.getInstance(Locale.CHINA);
try {
String updateStatement = "Update TransitRecordModel Set totalTradeAmt = totalTradeAmt + :plusVal where recordID > 2600 AND recordID < 2700";
curTransaction = curSession.beginTransaction();
int updateEntities = curSession.createQuery(updateStatement).setInteger("plusVal", 2).executeUpdate();
curTransaction.commit();
System.out.println("Update 成功,更新记录行 " + updateEntities);
} finally {
if (curSession != null) {
curSession.close();
}
}
}
? ?
SELECT t From TransitRecordModel t where t.details.tradeAmt > :tradeAmt
SELECT Distinct trm FROM TransitRecordModel trm inner join trm.details d where d.tradeAmt > 25
SELECT Distinct trm FROM TransitRecordModel trm inner join fetch trm.details d where d.tradeAmt > 25
list = curSession.createCriteria(TransitRecordModel.class)
.setProjection(Projections.projectionList()
.add(Projections.rowCount())
.add(Projections.avg("totalTradeAmt"))
.addOrder(Order.desc("createTime")).list();
for (Object obj : list) {
Object[] ele = (Object[]) obj;
System.out.println("RowCount=" + ele[0] + "\tTotalTradeAmt=" + ele[1]);
}
System.out.println("查询完成,查询共计 " + list.size() + " 行记录");
// 创建离线查询对象
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TransitRecordModel.class);
detachedCriteria.setProjection(Property.forName("totalTradeAmt"));
// 在指定的 Session 中查询
list = detachedCriteria.getExecutableCriteria(curSession).list();
System.out.println("TotalTradeAmt=" + obj);
? ?
? ?
标签:china test 英文 参数 calendar 策略 多个 where 微软
原文地址:http://www.cnblogs.com/li3807/p/6358384.html