kochcp wrote:
If you open up a new session, call session.load(User.class, userId), if that Id exists in the database then that object will be read from the database and persisted in that session for the lifetime of that session.
Just a minute, because I got confused now:). I thought that by using session.load(User.class, userId) Hibernate does not hit the database but gets the object from the session if exists there. My problem is if I have for example a
UserBean and a
UserDAO class:
UserBean
public User getUser() {
User user = session.getUser(User.class, userId);
userDao.checkUser(user.getId());
}
UserDAO
public User checkUser() {
session = sessionFactory.getCurrentSession();
session.load(User.class, userId);
What happens here? If checkUser is called after getUser I understand that the object is present in session
but if it is called after another method where session.getUser(User.class, userId)
is not called there won't I have an exception?
}