getCurrentSession打印出的hashCode不同
Configuration config = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session1 = sessionFactory.getCurrentSession();
Transaction transaction = session1.beginTransaction();
Student s = new Student("张三", "男", new Date(), "北京");
session1.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
System.out.println("session1的hashcode:"+connection.hashCode());
}
});
session1.save(s);
transaction.commit();
Session session2 = sessionFactory.getCurrentSession();
transaction = session2.beginTransaction();
s = new Student("李四", "男", new Date(), "上海");
session2.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
System.out.println("session2的hashcode:"+connection.hashCode());
}
});
session2.save(s);
transaction.commit();按理说两次打印的hashCode应该相同
但我打印出的不一样
session1的hashcode:1574258553
session2的hashcode:1774088918
求大神帮看下,我代码错了么?