我正在使用 Hibernate 插入数据并使用相同的会话获取数据,如下所示
StudentBean st1 = new StudentBean();
st1.setSid(513);
st1.setSname("Ravi)");
st1.setTotMarks(0.0f);
Session sess = factory.openSession();
sess.persist(st1);
StudentBean st2 = (StudentBean) sess.get(StudentBean.class, 510);
System.out.println(st2.getSname());
当我在休眠配置文件中使用 show_sql true 时,使用此行输出为
选择查询
Hibernate: select studentbea0_.sid1 as sid1_0_0_, studentbea0_.sname1 as sname2_0_0_, studentbea0_.tot_m1 as tot3_0_0_ from student1 studentbea0_ where studentbea0_.sid1=?
插入查询
insert into student1 (sname1, tot_m1, sid1) values (?, ?, ?)
任何人都可以告诉我为什么插入操作是由休眠引擎最后执行的,即使 Session.persist 在 get 方法之上?