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

Java

Avatar of undefined
Last Comment
for_yan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
for_yan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61