Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "illegal access to loading collection" error

Tags:

java

hibernate

When I execute my program without implementing hashcode() and toString() then it works fine. But as soon as I include hashcode() and toString() then I get this "illegal access to loading collection" error.

My hbm files are

1) booking.hbm.xml

<many-to-one name="userId" class="User" column="user_id"
        insert="true" update="true" cascade="save-update" >
    </many-to-one>
    <many-to-one name="flightId" class="FlightSchedule"
        column="flight_id" cascade="all" not-null="true">
    </many-to-one>

    <set name="passenger" table="passenger79215" lazy="false"
        inverse="true" cascade="save-update">
        <key column="reference_id" />
        <one-to-many class="Passenger" />
    </set>

2) Passenger.hbm.xml

<many-to-one name="referenceid" class="Booking" lazy="false"
        insert="true" update="true" column="reference_id "
        cascade="save-update">
    </many-to-one>

3) User.hbm.xml

<set name="booking" table="bookings79215" lazy="true"
        inverse="false" cascade="save-update">
        <key column="user_id" />
        <one-to-many class="Booking" />
    </set>

Can anyone explain the error?

like image 318
coderslay Avatar asked Oct 22 '11 13:10

coderslay


Video Answer


1 Answers

Your hashcode and equals methods are not working properly. Make sure that they are correct. toString() has nothing to do with collection classes but hashcode and equals does.

I assume that you have overridden both hashcode and equals and not only hashcode.

Object#hashCode() (Java Platform SE 7 )

like image 162
Ravi Bhatt Avatar answered Sep 28 '22 17:09

Ravi Bhatt