Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cascade and inverJoinColumn

 
Linwood Hayes
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I have the following tablessince employee and award are many-to-many relation we have

If we have


Questions:

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...
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic