-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate embeddable list mapping with identifier
PostPosted: Thu Apr 10, 2014 9:25 am 
Newbie

Joined: Thu Apr 10, 2014 9:16 am
Posts: 2
Hi guys,

I have a Person entity with an embeddable Address and there's a one-to-many relation between them (a person can have multiple addresses). The current mapping is something like this:

Code:
@Embeddable
public class Address { 
    // ... attributes
}

@Entity
public class Person {
    @ElementCollection(fetch = FetchType.EAGER)
    @JoinTable(name = "Person_addresses", joinColumns = @JoinColumn(name = "personid")
    )
    /*
    Attribute ovverrides with annotations
    */
    private java.util.Set<Address> addresses = new java.util.HashSet<Address>();   
}


Using this annotation means that in the database I have a Person_addresses table which contains all the address attributes and a personid. But it also means that if I have a person with an address list and I update the address list, Hibernate deletes all the related records and inserts them (the modified ones) again.

As far as I know there's a way to have a primary key in this table for each record - in this case hibernate can decide which item of the list needs to be updated. So my question is, how can I map an embeddable list with identifiers in the joining table? (I hope it's understandable what I want:)).

Thanks!
maestro


Top
 Profile  
 
 Post subject: Re: Hibernate embeddable list mapping with identifier
PostPosted: Fri Apr 11, 2014 5:39 am 
Newbie

Joined: Thu Apr 10, 2014 9:16 am
Posts: 2
Unfortunately it turned out, that JPA 2 does not support that. http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection#Primary_keys_in_CollectionTable


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.