zoukankan      html  css  js  c++  java
  • hibernate细节一

    public void saveUser(){
            Session session=JdbcUtil.getSession();
            User user=new User();
            user.setName("zjf2");
            user.setAddress("gzy2");
            Transaction tx=session.beginTransaction();
            user.setAge(23);
            user.setEmploy(1002);
            session.save(user);
            System.out.println(user);
            tx.commit();
            User user2=(User) session.get(User.class, user.getId());
            System.out.println(user2);
            System.out.println(user==user2);
            session.close();
        }

    ==============控制台信息

    Hibernate: select max(id) from user
    User [id=22, name=zjf2, age=23, address=gzy2, employ=1002]
    Hibernate: insert into user (name, age, address, employ, id) values (?, ?, ?, ?, ?)
    User [id=22, name=zjf2, age=23, address=gzy2, employ=1002]
    true

    ===============》第二次没有向数据库查询数据。两个对象相同

  • 相关阅读:
    github提交用户权限被拒
    vue数据响应式的一些注意点
    总结一下做移动端项目遇到的坑
    react-router
    promise-async-await
    递归函数
    Linux基础
    所有的数据处理都是map-reduce
    Mac下配置JAVA_HOME
    MySQL高级
  • 原文地址:https://www.cnblogs.com/ly-china/p/5537973.html
Copyright © 2011-2022 走看看