This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate annotations and joins Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate annotations and joins" Watch "Hibernate annotations and joins" New topic

Hibernate annotations and joins

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 69
I'd like to have this SQL statement implemented with Hibernate (using annotations)

select * from services serv left join campaigns camp on (serv.enterprise=camp.enterprise and serv.service=camp.service) where serv.service in (LIST) and serv.enterprise='enter';

so I've mapped the 2 entities and in the service class I have this field.

but doing this, the join is made using the ID and that is not wanted.

I've tried using @JoinColumns and it tries to create a Foreign key (not wanted) but it complains about using 2 columns in the foreign key.

"A Foreign key refering service from campaing has the wrong number of column. should be 1" this is the error when I use @JoinTable with 2 joincolumns alos the @JoinColumns provoke this error.

Edit: Neither enterprise nor service are IDs of neither table

I agree. Here's the link:
subject: Hibernate annotations and joins
Similar Threads
Simple JOIN in JPA proving difficult
Anyone know how to construct a one to many mapping with Hibernate / Java?
Orphan delete doesn't seem to be working properly
Hibernate - How to do associations with join tables?
Problem with joining of two tables with Hibernate