[Webinar] Learn how to a build a cloud-first strategyRegister Now


Hibernate with Spring Experts required.

Posted on 2005-04-14
Medium Priority
Last Modified: 2013-11-24
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 ??

Question by:letsbedecent
  • 2
  • 2

Author Comment

ID: 13782956
One more doubt raised during this experimentation is what did i loose by removing the equals and hascode methods ??
LVL 15

Accepted Solution

aozarov earned 1500 total points
ID: 13783675
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.

Author Comment

ID: 13833030
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 ??
LVL 15

Expert Comment

ID: 13881914
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.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question