Hibernate with Spring Experts required.

Posted on 2005-04-14
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

    Author Comment

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

    Accepted Solution

    Can you provide the stackTrace?
    You can read this 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

    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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Title # Comments Views Activity
    post4 challenge 28 70
    powerN  challenge 3 35
    strCopies  challenge 17 60
    for i loop in grovy 1 25
    I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    This video teaches viewers about errors in exception handling.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now