Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

hibernate annotation for mamy to many?

I am trying to annotate many to many.
I googled about the uni/bidirection manyto many association but I am a little confused.

1) Do you see difference between #1 & #2?
My understanding is #1 is bidirectional and #2 is unidirectional.
Can you clarify?

2) can you tell me what senarios you would use #1 and #2?

3)does it matter where I put this annotation?
I see some put before the property names and some put before the methods.
1)
public class Author {

@ManyToMany
@JoinTable(name="citation_author",
joinColumns={@JoinColumn(name="authorid")},
inverseJoinColumns={@JoinColumn(name="citationid")})
public List<Citation> getCitations() {return citations;}
}

public class Citation {
@ManyToMany
@JoinTable(name="citation_author",
joinColumns={@JoinColumn(name="citationid")},
inverseJoinColumns={@JoinColumn(name="authorid")})
public List<Author> getAuthors() {return authors;}
}


2)
public class Author {

@ManyToMany
@JoinTable(name="citation_author",
joinColumns={@JoinColumn(name="authorid")},
inverseJoinColumns={@JoinColumn(name="citationid")})
public List<Citation> getCitations() {return citations;}
}

public class Citation {
@ManyToMany
public List<Author> getAuthors() {return authors;}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial