博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hiberante链接查询的
阅读量:5142 次
发布时间:2019-06-13

本文共 3883 字,大约阅读时间需要 12 分钟。

System.out.println("+++++++++++++++++++++++++++++++++++++内连接+++++++++++++++++++++++++++++++++++++++++++++");        Configuration cfg=new Configuration().configure();        SessionFactory sf=cfg.buildSessionFactory();        Session session=sf.getCurrentSession();        Transaction ts = session.beginTransaction();        Query query = session.createQuery("select distinct d from  Dept d inner join d.emps");        List
dept=query.list(); for(Dept item : dept){ System.out.println(item.getDname()); for (Emp item1 : item.getEmps()){ System.out.println(item1.getEname()); } } System.out.println("+++++++++++++++++++++++++++++++++++++++迫切内连接+++++++++++++++++++++++++++++++++++++++++++"); query = session.createQuery("select distinct d from Dept d inner join fetch d.emps"); dept=query.list(); for(Dept item : dept){ System.out.println(item.getDname()); for (Emp item1 : item.getEmps()){ System.out.println(item1.getEname()); } } System.out.println("++++++++++++++++++++++++++++++++++++++++左外连接++++++++++++++++++++++++++++++++++++++++++"); query = session.createQuery("select distinct d from Dept d left outer join d.emps"); dept=query.list(); for(Dept item : dept){ System.out.println(item.getDname()); for (Emp item1 : item.getEmps()){ System.out.println(item1.getEname()); } } System.out.println("++++++++++++++++++++++++++++++++++++++++++迫切左外连接++++++++++++++++++++++++++++++++++++++++"); query = session.createQuery("select distinct d from Dept d left outer join fetch d.emps"); dept=query.list(); for(Dept item : dept){ System.out.println(item.getDname()); } System.out.println("++++++++++++++++++++++++++++++++++++++++++右外连接++++++++++++++++++++++++++++++++++++++++"); query = session.createQuery("select distinct d from Dept d right outer join d.emps"); dept=query.list(); for(Dept item : dept){ System.out.println(item.getDname()); for (Emp item1 : item.getEmps()){ System.out.println(item1.getEname()); } } System.out.println("++++++++++++++++++++++++++++++++++++++++++批量增加++++++++++++++++++++++++++++++++++++++++"); session=sf.getCurrentSession(); ts = session.beginTransaction(); query = session.createQuery("insert into Dept(dname) Select d.dname from Dept d "); query.executeUpdate(); ts.commit();// System.out.println("++++++++++++++++++++++++++++++++++++++++++批量删除++++++++++++++++++++++++++++++++++++++++");// query = session.createQuery("delete from Dept d where d.did>2");// query.executeUpdate();// ts.commit(); System.out.println("++++++++++++++++++++++++++++++++++++++++++批量修改++++++++++++++++++++++++++++++++++++++++"); session=sf.getCurrentSession(); ts = session.beginTransaction(); query = session.createQuery("update Dept d set d.dname='hah' where d.did>2"); query.executeUpdate(); ts.commit(); System.out.println("++++++++++++++++++++++++++++++++++++++++++批量删除(sql)++++++++++++++++++++++++++++++++++++++++"); session=sf.getCurrentSession(); ts = session.beginTransaction(); Work work=new Work() { @Override public void execute(Connection connection) throws SQLException { PreparedStatement preparedStatement = connection.prepareStatement("DELETE depts where did>?"); preparedStatement.setObject(1,2); preparedStatement.executeUpdate(); } }; session.doWork(work); ts.commit(); }

 

转载于:https://www.cnblogs.com/www-datou-com/p/6374573.html

你可能感兴趣的文章
Shiro入门 - 通过自定义Realm连数数据库进行授权
查看>>
C语言复习笔记-17种小算法-解决实际问题
查看>>
面向过程思想理解:
查看>>
20171020java学习总结——execl 批量导入
查看>>
如何自绘树形控件(QQ好友列表)
查看>>
web异步开发——ajax
查看>>
通过修改VHD文件的位置来提升性能
查看>>
将WPF版的弹幕播放器给优化了一下
查看>>
Qt5 动态库的创建与使用
查看>>
面向对象设计
查看>>
Sqoop迁移Hadoop与RDBMS间的数据
查看>>
[label][JavaScript]读nowmagic - js词法作用域、调用对象与闭包
查看>>
模板模式
查看>>
PAT 1014 福尔摩斯的约会
查看>>
ssh2整合中的一些问题
查看>>
hibernate Expression详解
查看>>
LeetCode #303. Range Sum Query
查看>>
oracle 自增序列实现 可作为主键
查看>>
STM32----stlink口
查看>>
Android viewpager切换到最后一页时,跳转至其他activity
查看>>