I had my problems too, especially finding a "business key" for every
entity, as the hibernate team proposes. Finally, I picked up the idea of
implementing equals and hashcode using the obect's id, and a random
identifier on newly created objects.

For this purpose I have a base class for all objects, that are
identified by Long ids. See the attached file, if you're interested in a
AppFuse-ready class.

The idea is from the following site:
http://www.avaje.org/equals.html#gerry

There you'll find a much more concise overview over all the
possibilities, compared to reading the whole discussion on the hibernate
site.

Kind regards,
Tobias



________________________________

Von: Michael Horwitz [mailto:[EMAIL PROTECTED] 
Gesendet: Montag, 30. Juli 2007 09:45
An: users@appfuse.dev.java.net
Betreff: Re: [appfuse-user] LazyInitializationException: illegal access
to loading collection....


I have had a lot of problems in impelementing equals/hashcode,
particularly on entities that I wanted to include in a set. I found at
one stage that hibernate was instantiating the entity, adding it to the
set, and only then setting its properties. The net result is that the
hashcode changed between the time the entity was added and it was
accessed. I'm afraid I just gave up and returned 0 as the hashcode for
all persistent entities.... 
 
Mike
 
On 7/27/07, Daniel.Rodriguez <[EMAIL PROTECTED]> wrote: 


        Matt & Michael,
        
        It seems I finally found a solution
        
        Checking again thru the logs I noticed that the exception was
raised 
        everytime that my entity hashcode's method was called.
        So I rechecked the Hibernate folks discussion on Equals and
Hashcodes at
        http://www.hibernate.org/109.html .
        
        What I basically did was that I modified commonclipse hashcode
to remove the
        references to the conflicting collection.  Voila, that did the
job (and
        according to my junit tests, it works flawlessly so far). 
        
        I also read about using UUID in the Equals/Hashcode on the same
site.
        
        It's not ideal (it's a JUST WORKS tm solution) so I wanted to
hear what are
        your opinions on the matter.
        
        Thanks.
        -- 
        View this message in context:
http://www.nabble.com/LazyInitializationException%3A-illegal-access-to-l
oading-collection....-tf4152650s2369.html#a11833906
<http://www.nabble.com/LazyInitializationException%3A-illegal-access-to-
loading-collection....-tf4152650s2369.html#a11833906> 
        Sent from the AppFuse - User mailing list archive at Nabble.com.
        
        
---------------------------------------------------------------------
        To unsubscribe, e-mail: [EMAIL PROTECTED]
        For additional commands, e-mail: [EMAIL PROTECTED]
        
        


Attachment: BaseObjectIdentified.java
Description: BaseObjectIdentified.java

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to