下面看個示例:
public listfindmenusbyentitytypeid(long id) ,m.name as ,m.url as ,m.icon_url as ,m.parent_id as ,"
+"m.serial_number as ,m.admin as ,m.system_admin as ,m.program_name as "
+" from menu m, entity_type et, entity_admin_menu eam"
+" where et.id = "+id+""
+" and m.program_name = '"+globalnames.program_name_chss+"'"
+" and et.id = eam.entity_id"
+" and m.id = eam.menu_id";
listmenus = super.getsessionfactory().getcurrentsession().createsqlquery(hql).addentity("menu",menu.class).list();
return menus;
}
public listfindmenusbyentitytypeid(long id) ,m.name as ,m.url as ,m.icon_url as ,m.parent_id as ," +"m.serial_number as ,m.admin as ,m.system_admin as ,m.program_name as " +" from menu m, entity_type et, entity_admin_menu eam" +" where et.id = "+id+"" +" and m.program_name = '"+globalnames.program_name_chss+"'" +" and et.id = eam.entity_id" +" and m.id = eam.menu_id"; listmenus = super.getsessionfactory().getcurrentsession().createsqlquery(hql).addentity("menu",menu.class).list(); return menus; }1.通過addentity("menu",menu.class),通過addentity把要返回的資料強轉為menu,注意menu必須要是配置hibernate映**的。m.id as ,這是為了如果資料庫欄位名和menu模型中不一樣所以都as取了個別名,那麼這樣就能返回menu物件了。
mysql執行語句 mysql執行sql語句過程
流程概述 mysql得到sql語句後,大概流程如下 1.sql的解析器 負責解析和 sql 2.預處理器 對解析後的sql樹進行驗證 3.查詢優化器 得到乙個執行計畫 4.查詢執行引擎 得到資料結果集 5.將資料放回給呼叫端。流程圖如下所示 分發器及快取階段 首先,如果系統的快取功能開啟著的話,sq...
Hibernate執行sql相關問題
1.查詢 1 利用hibernate提供的sqlquery物件執行。即可以通過session物件的createsqlquery 方法獲取。如 string sql select from product limit 0,10 sqlquery query session.createsqlquery...
三 Hibernate 執行複雜的sql
1 使用sql查詢 使用sql查詢可以通過兩種方式來實現 1 利用hibernate提供的sqlquery物件執行。即可以通過session物件的createsqlquery 方法獲取。如 string sql select from product limit 0,10 sqlquery quer...