'Hibernate getNewSession, can see object non-commit changed value, why?

Session session = HibernateUtil.getCurrentSession();
ResAddr resAddr = resAddrHome.findById(1);
......
resAddr.setAddress(address);
resAddr.setStartDate(startDate);
resAddr.setDistrict(district);          
resAddrHome.merge(resAddr);
session.flush();
Session newSession = HibernateUtil.getNewSession();  // <--
Query query = newSession.createQuery("from resAddr");
query.list();
  1. I have updated resAddr, then merge it, but not commit yet, then I open a new Hibernate Session by HibernateUtil.getNewSession(), then I find I can see the uncommitted change of previous resAddr, why? getNewSession() does not get a new connection?

  2. then what is getNewSession() different from getCurrentSession()?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source