hql是hibernate自己的一套查詢語言,於sql語法不同,具有跨資料庫的優點。示例**:
// 獲取檢查單例項列表
string tplsql = "from checkformtemplate t where t.type=-1 and t.id in("+ instanceidstr +")";
session session = getsession();
return session.createquery(tplsql).list();
long count = (long) session.createquery("select count(*) from checkformtemplate where type=-1").uniqueresult();
//傳遞引數
string result = (string) session .createquery("select result from checkformtemplate where id=:id")
.setparameter("id", id)
.uniqueresult();
list list = session
.createquery("from checkform where dataid=:id order by checkitem,checknote")
.setparameter("id", id)
.list();
//刪除
session.createquery("delete from dictentity").executeupdate();
string hql = "delete basicdataobject where id = '" + id + "'";
string sql = "delete from data_object_basic_old where id = '" + id
+ "' and owner_id = '" + ownerid + "'";
try {
this.gethibernatesession().createquery(hql).executeupdate();
this.gethibernatesession().createsqlquery(sql).executeupdate();
//查詢
//分頁查詢
//createsqlquery查詢
string sql = "insert into sys_team (description, " +
"jianpin_name, " +
"parent_id, " +
"pinyin_name, " +
"project_id, " +
"project_type, " +
"row_create_client, " +
"row_create_time, " +
"row_creator, " +
"row_sort_order, " +
"row_update_client, " +
"row_update_time, " +
"row_updater, " +
"team_code, " +
"team_name, " +
"team_id) values ('',:jianpinname,:parentid,:pinyinname, :projectid, :projecttype, :createclient, :createtime, :creator, :sortorder, :updateclient, :updatetime, :updater, '', :teamname, :teamid)";
session session = this.gethibernatesession();
session.createsqlquery(sql)
.setparameter("jianpinname", team.getjianpinname())
.setparameter("parentid", team.getparentid())
.setparameter("pinyinname", team.getpinyinname())
.setparameter("projectid", team.getprojectid())
.setparameter("projecttype", team.getprojecttype())
.setparameter("createclient", team.getrowcreateclient())
.setparameter("createtime", team.getrowcreatetime())
.setparameter("creator", team.getrowcreator())
.setparameter("sortorder", team.getrowsortorder())
.setparameter("updateclient", team.getrowupdateclient())
.setparameter("updatetime", team.getrowupdatetime())
.setparameter("updater", team.getrowupdater())
.setparameter("teamname", team.getteamname())
.setparameter("teamid", team.getteamid())
.executeupdate();
string sql = "update commnct_notice_notification cnn set cnn.filesize = '"
+ filesize
+ "', cnn.filepath = '"
+ filepath
+ "', cnn.deleteflag = '', cnn.notification_security = '"
+ notificationsecuritylevel
+ "', cnn.notification_num = '"
+ notificationnum
+ "', cnn.model_identification = '"
+ notificationmodelidentify
+ "', cnn.notification_company = '"
+ notificationcompany
+ "', cnn.notification_drawing_num ='"
+ notificationdrawingnum
+ "', cnn.notification_replace = '"
+ notificationreplace
+ "' where cnn.pid = '"
+ notificationvo.getnotificationdocid()
+ "' and cnn.noticeid = '"
+ notificationvo.getnotificationid()
+ "'";
int updatecount = getnotificationdao().gethibernatesession()
.createsqlquery(sql).executeupdate();
posted @
2016-03-24 11:22
赤子之心_timefast 閱讀(
...)
編輯收藏
Hibernate的條件查詢的幾種方式
1 第一種,用?佔位符,如 登入 用?佔位符 public listloginuser userpo up throws exception 2 用 命名 佔位符,如 登入 用 命名 佔位符 public listloginuser2 userpo up throws exception 2.1 使...
hibernate資料查詢的幾種方式
1.使用主鍵id載入物件 load get 2.通過物件導航,比如通過stu.getteam 得到team的例項 3 使用hql 4使用qbc query by criteria 5直接使用sql語句取得記錄集 一般都使用後面三種方式.注意.hql是物件導向的查詢.語法和sql是基本一樣的.不區分大...
hibernate資料查詢的幾種方式
1.使用主鍵id載入物件 load get 2.通過物件導航,比如通過stu.getteam 得到team的例項 3 使用hql 4使用qbc query by criteria 5直接使用sql語句取得記錄集 一般都使用後面三種方式.注意.hql是物件導向的查詢.語法和sql是基本一樣的.不區分大...