Let's say I have the following tablessince employee and award are many-to-many relation we have
If we have
1. If we DON'T specify "Cascade" in many-to-many mapping or configuration file, then when we do session.save(employee), is it true it will only save "employee" data into Employee table, and will NOT save the associated "award" data into Award table ? How about the "EMployee_AWARD" link table ?
2. Confusion about "inverseJoinColumn", two things:
if we set "inverseJoinColumn" as follows:
a) If this is a uni-directional relation, i.e. we only include "Award" in Employee class (but don't include Employee in Award class), then do we need to specify this "inverseJoinColumn" in Employee class ?
b) If we have a bidirectional bahavior, i.e. we let "Employee" and "Award" classes include each other (<Set>) as class attributes, then we need to specify "inverseJoinColumn" anyway, correct ?
Overall, I am just confused when this "inverseJoinColumn" is needed and not needed...
Linwood Hayes wrote:Overall, I am just confused when this "inverseJoinColumn" is needed and not needed...
Did you already check the Java Persistence API WikiBook? When I'm having an issue with JPA, JPQL, or something related it's the first resource I'll check to find a solution. It's really an excellent resource (in my humble opinion)! It's not a step-by-step tutorial, but you'll find everything required in this wiki book with illustrative code snippets and very good explanations: from basic entity mappings to complex JPQL queries. Here is the section about the ManyToMany relationship.
Hope it helps!
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop