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

Convert this 3 table join into JPA?

 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm relatively new to the Java Persistence API and I'm having some trouble converting my sql into JPA annotations. I would like to use JPA annotations to reproduce this example SQL:


I kinda understand how to use @SecondaryTable to join together PEOPLE and SALARY, but I'm stuck on how to join together SALARY and SALARY_TYPE. Code examples would be much appreciated.
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Michael, you need to understand that that JPA-QL need to know how to reach from People to Salary and/or to Salary Type. If you have an Entity named People and a single sided property named Salary the JPA-QL can reach the table Salary either y you use @Basic, @Many-to-One, @One-to-One or @One-to-Many. Like this



Regarding SalaryType it's the same but the mapping it's easier it is a simple property and not an entity. This it's how the JPA-QL can reach from Payment to Salary or even to SalaryType.

 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you clarify what you mean by saying that salary type is simplier because it's a property and not a mapping? What confuses me from the example (and I know it's just an example) is I'm expecting salaryType to be a String not a SalaryType object.
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i mean is that if SalaryType was an Entity (marked with @Entity) and not an String or int or any other type that doesn't need the annotation, it's easier to implement.

And true, i made a mistake. The code should be like this



As a recomendation if the salaryType it's a small list of choices, then, you could use an enumeration.
[ December 03, 2008: Message edited by: Angel Taveras ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic