Hibernate with Spring Experts required.

Hello all,

           I am using spring over hibernate. When i defined my objects (model objects/POJO's whatever) i have an equals, hashcodebuilder etc., defined for them using commons package helper classes.  

           I defined the relationships using hibernate XDoclet tags.

           When i am trying to access the one-to-many (many part) of a relation in a jsp it gives lazy initialization exception. Ex : Cat, Kittens (1 cat many kittens).
I have getKittens() in my Cat Object definition obviously. So, in my jsp when i am trying to access this collection that exception is thrown. I have the open session in view filter and all required for spring.

          When i removed the equals, Hashcode builder etc., from the objects, this works, i wonder why !!! Can anyone tell me why this is an obstacle for Hibernates lazy initialization using spring ??

Who is Participating?
aozarovConnect With a Mentor Commented:
Can you provide the stackTrace?
You can read this http://www.hibernate.org/109.html to see why and when it is important.
Basically, unless you want to different instances to be considered equal (based on their values) there is no need to provide it.
letsbedecentAuthor Commented:
One more doubt raised during this experimentation is what did i loose by removing the equals and hascode methods ??
letsbedecentAuthor Commented:
Normally, two different instances will never be equal in this case right., because the id is generated by auto-increment algorithm and rows will never be equal !!

So is there really a need to write those methods ??
You can have a case where you load the same object (with the same id) by two different Sessions.
If you want those two instances (which represent the same row in the DB) to be equal then you will need to provide equals/hashCode.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.