Hi!
I am using Spring with Hibernate, and i am confused by the following (taken from a junit test):
I read the Hibernate manual on Identity/Equals, and i thought that the two find's should return exactly the same object (in terms of Java-VM identity). Am i wrong about that?Code:Subject subject1a = (Subject) getHibernateTemplate().find("FROM Subject s WHERE s.title='Subject 1'").get(0); Subject subject1b = (Subject) getHibernateTemplate().find("FROM Subject s WHERE s.title='Subject 1'").get(0); // the following fails! assertTrues(subject1a==subject1b);
I tried the same with a "plain" Hibernate session:
And this works. I thought HibernateTemplate would store the HibernateSession in a thread bound variable and reuse it on the next call. But apparently in the first code snippet a new session is opened for every find-call.Code:Subject subject1a = (Subject) hibernateSession.find("FROM Subject s WHERE s.title='Subject 1'").get(0); Subject subject1b = (Subject) hibernateSession.find("FROM Subject s WHERE s.title='Subject 1'").get(0); // the following is true! assertTrue(subject1a==subject1b);
Did i miss something important?
I will post more information about my setup below.
Thanks for your help!
Sebastian


Reply With Quote