troubleshooting Question

hibernate annotation for mamy to many?

Avatar of dkim18
dkim18 asked on
Java
1 Comment1 Solution266 ViewsLast Modified:
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;}
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros