I'm having some problems with a many to many association.
Looks like hibernate thinks it's a many to one association when running the query under. It's trying to join on a non existing foreign key in the Group table instead of a key in the association table.
Am i missing something?
Magnus
---------------------
public class Contact {
....
@ManyToMany(mappedBy="contacts")
public Set<Group> getGroups() {
return groups;
}
...
}
public class Group {
...
@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})
public Set<Contact> getContacts() {
return contacts;
}
...
}
List<Contact> list = session.createQuery("from Contact contact where contact.groups.size = 0").list();
Hibernate: select contact0_.contactId as contactId, contact0_.address as address5_, contact0_.country as country5_, contact0_.firstname as firstname5_, contact0_.lastname as lastname5_, contact0_.postcode as postcode5_, contact0_.city as city5_, contact0_.email as email5_, contact0_.phone as phone5_, contact0_.mobile as mobile5_, contact0_.user_userId as user11_5_ from Contact contact0_, _Group group2_, _Group_Contact groups1_ where contact0_.contactId=groups1_.contacts_contactId and groups1_.groups_groupId=group2_.groupId and (select count(group2_.contacts_contactId) from _Group_Contact groups1_, _Group group2_ where contact0_.contactId=groups1_.contacts_contactId and groups1_.groups_groupId=group2_.groupId)=0
22.05 00:28:32 WARN (JDBCExceptionReporter) SQL Error: 1054, SQLState: 42S22
22.05 00:28:32 ERROR (JDBCExceptionReporter) Unknown column 'group2_.contacts_contactId' in 'field list'
|