Sebastian
Aug 25th, 2004, 04:59 AM
Hi!
I am using Spring with Hibernate, and i am confused by the following (taken from a junit test):
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 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?
I tried the same with a "plain" Hibernate session:
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);
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.
Did i miss something important?
I will post more information about my setup below.
Thanks for your help!
Sebastian
I am using Spring with Hibernate, and i am confused by the following (taken from a junit test):
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 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?
I tried the same with a "plain" Hibernate session:
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);
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.
Did i miss something important?
I will post more information about my setup below.
Thanks for your help!
Sebastian