綜合知識

當前位置 /首頁/綜合知識 > /列表

hibernate的hql語句怎麼寫

1. 用hibernate的HQL怎麼寫一個插入語句

不是有映射文件嗎?比如你的數據庫表為student那麼的你就應該有hibernate.cfg.xml配置文件和他的映射文件hibernate.hbm.xml,最後還應該有一個student表的映射類student.java這3個文件.然後你建一個實現類studentInsert實現是SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); student st=new student(); st.setId("0001"); st.setUserName("Wang"); st.setpassWord("123"); session.save(st); tx.commit(); session.close();就是這樣。

hibernate的hql語句怎麼寫
2. 用hibernate的HQL怎麼寫一個插入語句

不是有映射文件嗎?

比如你的數據庫表為student

那麼的你就應該有hibernate.cfg.xml配置文件和他的映射文件hibernate.hbm.xml,最後還應該有一個student表的映射類student.java

這3個文件.

然後你建一個實現類studentInsert

實現是

SessionFactory sf = new Configuration().configure().buildSessionFactory();

Session session = sf.openSession();

Transaction tx = session.beginTransaction();

student st=new student();

st.setId("0001");

st.setUserName("Wang");

st.setpassWord("123");

session.save(st);

tx.commit();

session.close();

就是這樣.

3. 求寫一條hibernate的hql語句

再套一層,select * from Tbobject where order_id in (。.你的一列數據)

HQL這樣寫

select * from TbOrder where t.id.orderId in (select distinct t.id.orderId from TbOrder t where t.tbViperson.viCardno=1)

-------------------------貌似不對奧----------

這樣,我以前SQL語句這樣寫過,

select distinct t.id.orderId ,max(列1),max(列2),max(列3) from TbOrder t where t.tbViperson.viCardno=1

4. 求寫一條hibernate的hql語句

再套一層,select * from Tbobject where order_id in (。

.你的一列數據)HQL這樣寫select * from TbOrder where t.id.orderId in (select distinct t.id.orderId from TbOrder t where t.tbViperson.viCardno=1)-------------------------貌似不對奧----------這樣,我以前SQL語句這樣寫過,select distinct t.id.orderId ,max(列1),max(列2),max(列3) from TbOrder t where t.tbViperson.viCardno=1。

5. hibernate 查詢表中最後一條語句的hql怎麼寫

select * from table

where rownum<(select count(*)+1 from table)

minus

select * from table

where rownum<(select count(*) from table)

也可以簡化為

select * from table

minus

select * from table

where rownum<(select count(*) from table)

效果是一樣的

切記rownum是偽列 只能用<

順便給你求第X行的通用SQL語句

select * from table where rownum<X+1

minus

select * from table where rownum<X

6. hibernate查詢表中最後一條語句的hql怎麼寫

select * from tablewhere rownum<(select count(*)+1 from table)minusselect * from tablewhere rownum<(select count(*) from table)也可以簡化為select * from tableminusselect * from tablewhere rownum<(select count(*) from table)效果是一樣的切記rownum是偽列 只能用<順便給你求第X行的通用SQL語句select * from table where rownum7. hql語句怎麼寫

String hql="from 類名 where app=6 AND pro_read_flag=FALSE";

Query query=session.createQuery(hql);

或者

String hql="from 類名 where app=? AND pro_read_flag=?";

Query query=session.createQuery(hql);

query.setParameter(0,6);

query.setParameter(1,false);

8. Hibernate中的HQL語句

首先要説的是,hibernate操縱的都是對象。所有第一條,你必須有一個javaBean,如是Cat, 有a和b屬性,有對應的get和set方法,通過new Cat('xyz',123);創建一個Cat對象cat,然後調用hibernate的session.save(cat);就ok了。第二條:首先要根據id把對象加載上來,然後更新,如:Cat cat = session.load(Cat.class,1),cat.setA('x');此時Cat類中必須有id和a屬性,有相應的get,set方法。第三:先把對象加載上來,然後刪除:Cat cat = session.load(Cat.class,'3'); session.delete(cat);

第四:就是根據Test對象的某個屬性查詢,返回的是Test對象的集合。

第五,沒發現dao和table有啥聯繫

TAG標籤:hql 語句 hibernate #