users@glassfish.java.net

Re: Self referential ManyToMany relationship

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Fri, 12 May 2006 19:54:56 -0700

Hi Dibyendu,

You shouldn't need the 'mappedBy' as it is used to define the other side,
that is responsible for the FK updates.
But we most probably don't have such tests - our self-refs test are usually
1-M relationship, like Employee-Manager.

regards,
-marina

Dibyendu Majumdar wrote:
> Hi,
>
> I am trying to implement a self referential many to many relationship.
> Is following code correct?
>
> @Entity
> public class Book {
>
> @Id @GeneratedValue(strategy=GenerationType.AUTO)
> Long bookId;
> @Version
> Long version;
> @ManyToMany(mappedBy="linkedBooks")
> Collection<Book> linkedBooks;
>
> public Collection<Book> getLinkedBooks() {
> return linkedBooks;
> }
>
> public void setLinkedBooks(Collection<Book> linkedBooks) {
> this.linkedBooks = linkedBooks;
> }
>
> public Long getBookId() {
> return BookId;
> }
>
> public void setBookId(Long BookId) {
> this.BookId = BookId;
> }
>
> public Long getVersion() {
> return version;
> }
>
> public void setVersion(Long version) {
> this.version = version;
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>