1

I have 3 tables:

Project.id
Project.name
Cost.id
Cost.price
CostLink.cost_id
CostLink.table_name
CostLink.table_id

my query:

SELECT *
FROM Project p
JOIN CostLink l on p.id = l.table_id and l.table_name = 'PROJECT'
JOIN Cost c on l.cost_id = c.id

My question is , how do i create my Cost and Project entities in hibernate to use this polymorphic link table?

I'm using dropwizard with hibernate. Much thanks in advance!

Gary
  • 7,167
  • 3
  • 38
  • 57
  • I havent tried anything because i dont know how to create such relationship. i got other relationship done, but they are simple one to one or one to many without polymorphic tables. I have looked at the hibernate docs, and i think the answer is to use @Any annotation, but i'd love to see a few examples – Alexey Volochenko Dec 04 '12 at 02:33
  • Look at [this answer](http://stackoverflow.com/questions/2252468/hibernate-criteria-and-multiple-join/5095187#5095187), it will explain how to do JOINs. – mindas Dec 04 '12 at 11:36

0 Answers0