Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] re move() and a OneToMany mapping with CascadeType.PERSIST

Interesting.  Please log a bug that clear() in IndirectSet should call
clear() after recording the removal of the objects in-case of an identity
change.

Changing your objects hashCode after putting it into a Set or Map is not a
good idea in general.  You should either ensure the Id is assigned before
putting it into the Set, or rely on Object equals/hashCode instead of your
Id.



patric-7 wrote:
> 
> The problem is that the hashCode() of my entity changes during the
> transaction
> resulting in that the entity is unequal to the backup clone.
> (so the entity is changed and removed at the same time)
> 
> I am using the "business-Id" as the identity of an entity for equals()  
> and hashCode().
> 
> As a consequence that the IndirectSet delegate cannot find the  
> hashCode in the approriate hash bucket when calling Iterator.remove().
> 
> I have two questions:
> 
> 1. Shouldn't IndirectSet.clear() rely on the delegate's clear() method  
> instead of removing all elements using an iterator which fails in the  
> above mentioned case.
> Currently IndirectSet seems to violate the Set interface contract  
> which guarantees that clear() will remove all objects.
> 
> 2. What is recommended/best way for implementing equals() / hashCode()  
> in JPA/EclipseLink entities?
> I can see three options:
> a) business-ID (all non-technical fields, without PK and FKs)
> b) primary key
> c) rely on Object.equals() / Object.hashCode()
> 
> Thank you and best regards,
> 
> Patric
> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/remove%28%29-and-a-OneToMany-mapping-with-CascadeType.PERSIST-tp30785713p31050497.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top