您的位置:首页 > 数据库

hibernate执行sql语句步骤

2016-09-11 20:34 295 查看
要先用hibernate执行sql语句,必须先配置好Session。下面看下配置Session的方式。1.初始化hibernate的配置管理类Configuration。2.通过Configuration类来创建sessionFactory。3.通过sessionfactory生成session实例。整个步骤大概为

Configuration config=new Configuration().configure();
SessionFactorysessionFactory=config.buldSessionFactory();
Session session=sessionFactory.openSession();
//hql查询
Query query=session.createQuery(“fromtable where id=1”);
//sql查询
Query query=session.createSQLQuery(“select * from table where id=1”);
先简略的讲一下,以后再补详细- -
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: