May 16th, 2007, 10:30 PM
Problem with HibernateTemplate's find method
I am using Hibernate with spring.I have got a table that has person_number as the id and person_status and effective_date as other columns.I can have two entries for the same person_number but the effective_date has to be different.
In my app I am trying to get the status of a person with the effective_date and I am making the following call in my DAO layer:
getHibernateTemplate.find("from PERSON where person_number = ?",person_number);
The problem that I am facing is that it is returning a List having the same person object even though my table has to different entries for the same person number.
Can anybody suggest me any solution for that.I guess I know the problem.Its somewhat related with the first level cache of Hibernate.But I dont know the solution.Hence please help me in this.Thanks in advance.
May 17th, 2007, 06:34 AM
I'm not sure I understand your problem. You receive a List of what?? Your person table can contain the same IDs and you retrieve multiple items, isn't that expected?
May 17th, 2007, 08:49 AM
Thanx for the reply.In more details,I have Person Pojo which is made to hold the information of a person from the Person_table.The identifier or the "id" is the person_number.I am trying to get information from the person_table with the Person_number and I am making a getHibernateTemplate().find("from Person where person_number = ?",personNumber).Ideally this should return a List containing Person objects.And it is also kind of doing the same thing but instead of returning a list containing different person objects,having the same personNumber,it is returning a list contaning the same object.For example lets say there are two entries in the DB with the personNumber as "1234" but the columns "effective_date" and "person_status" hold different values.The list that I am getting has the size two but contains objects which have the same information not the different ones.Now thats kind of problem that I am entangled into.
Hope I have made my problem clear.
May 17th, 2007, 12:18 PM
Ok, it would be useful to see the HBM mapping file or the POJO if you are using annotations.