1. hibernate添加语句怎么写
不是有映射文件吗?
比如你的数据库表为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();
就是这样.
2. hibernate基本语句怎么操作
你既然用了hibernate就用第一种写法,
用第二种写法和不用hibernate有啥区别,不用hibernate就是要先开Connection然后开事物,保存,提交事物,然后关闭连接
你既然用了hibernate就完全不用用第二种方法,因为这些操作在getHibernateTemplate().save();里都已经封装好了,如果你非要用下面的写法也没办法,不是不行,只是跟只用jdbc有什么区别
hibernate3没有用过,但是如果没有find的话hibernate也是很好用的,抛开criteria不说
hql:
集合:this.getSession().createQuery("hql语句").list();
单一结果:this.getSession().createQuery("hql语句")uniqueResult();
有参数this.getSession().createQuery("hql语句").setString(0,"xxx").setString(1,"xxx").list();
sql:
this.getSession().createSqlQuery("sql语句")
其他一样
3. 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);
转载请注明出处育才学习网 » hibernate语句怎么写