Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Customizing delete calls before updating a ElementCollection

The issue is that JPA does not allow you to define a primary key or unique
set of fields when using Embeddable in a ElementCollection.  This makes
using ElementCollections very difficult as you rarely want to compare on
every field, and normally have a primary key or unique set of fields.

EclipseLink however does support this,  you should be able to use the
EclipseLink @PrimaryKey annotation or a DescriptorCustomizer to set the
primary key for the Label descriptor to just the "BOX_ID_FPK" and "TEXT"
columns.

Otherwise you would need to convert the ElementCollection to a OneToMany and
the Embeddable to an Entity.



Rob C wrote:
> 
> Hi I have the following:
> 
> @Entity
> @Table(name="BOX")
> public class Box {
>     @Id
>     @Column(name="BOX_ID")
>     private int id;
>     
>     @ElementCollection
>     @CollectionTable(name="BOX_LABEL",
> joinColumns=@JoinColumn(name="BOX_ID_FPK", referencedColumnName="BOX_ID"))
>     protected List<Label> labels;
> }	
> 
> 
> @Embeddable
> public class Label {
>     @Column(name="TEXT")
>     private String text;
>     
>     @Column(name="IS_DELIVERED")
>     private boolean delivered = false;
> 	
>     @Column(name="PROPERTIES")
>     Properties properties;
> }	
> 
> If I update a Box entity containing a list of Labels all Labels are
> deleted (as expected) and then the new Labels are inserted. 
> My problem arises when EclipseLink attempts to delete the Label rows. It
> calls for instance:
> FIN: DELETE FROM BOX_LABEL WHERE ((((TEXT = ?) AND (IS_DELIVERED = ?)) AND
> (PROPERTIES = ?)) AND (BOX_ID_FPK = ?))
>         bind => [Books, true, [B@1295fe8, 10]
> The Properties column is persisted as a Blob and the delete call above
> will fail and the row will not be deleted. No error messages are
> displayed.
> What I would like to do is to in some way modify this delete call to
> ignore the properties column. In that case the row will be deleted.
> When I annotated the properties field as @Transient then the row is
> deleted. But I dont want to mark it as Transient. I need the Properties
> value. 
> In my model a text field is unique within a ElementCollection.
> Any clues?
> 


-----
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 
-- 
View this message in context: http://old.nabble.com/Customizing-delete-calls-before-updating-a-ElementCollection-tp29181969p29336041.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top