Link to home
Start Free TrialLog in
Avatar of letsbedecent
letsbedecent

asked on

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 ??

Thanks.
Avatar of letsbedecent
letsbedecent

ASKER

One more doubt raised during this experimentation is what did i loose by removing the equals and hascode methods ??
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.