当前位置:懂科普 >

综合知识

> hibernate的hql语句怎么写

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有啥联系

标签: 语句 hql hibernate
  • 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/zonghezhishi/ew94wn.html