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

Table Join without Foreign Key

 
Richard Roszak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to join 2 tables that do not have a Foreign Key relationship with Object Relational Mapping?

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, using something like HQL (if Hibernate is your ORM of choice).
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any ORM you can always join the two tables,, even if their association is not mapped. You can do this with theta-style joins. This is where you state the columns to join on in the WHERE clause. You can also use theta-style joins even when they are mapped too.

Simple example the join field is "name"

SELECT a
FROM A a, B b
WHERE a.name = b.name


Mark
 
Richard Roszak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see how I can do this with:



But not sure how or whether I can do this in an ORM.xml file? This does not work for me:



Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic