• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Examples for outer join in JPA?

 
Pierre Rehnberg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I have two tables

Table 1
ID Name
1 Adam
2 Richard
3 Sam
4 Bill
5 Kyle
6 Whopper
7 Nicolas
8 Stephen
9 Jill


Table 2
LastName
Connor
O'Reilly
Baker


Using JPA I want to use Class A mapping to Table 1 and being abstract.
Class B mapping to Table 2 and extending Class A.
When quering Class B I want to get all results in Class A and a NULL value where the LastName is missing.

How do I do this?

I have gotten this far.

 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joined inheritance in JPA requires a row in both tables. Depending on your JPA provider there may be a way to do it, but it is a bad design in general.

Either ensure there is a row in last name always, or map it as a OneToOne instead.

Also you need an ID in the secondary table.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Tables#Multiple_table_outer_joins
 
Pierre Rehnberg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James.

Then it is as I suspected.

cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic