-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Many to many association.
PostPosted: Sat May 21, 2005 7:03 pm 
Newbie

Joined: Sat May 21, 2005 6:47 pm
Posts: 3
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'


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 23, 2005 12:09 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 5:25 am
Posts: 48
Location: Delhi, India
where you specified association table?

look at this link http://hibernate.org/~emmanuel/doc/#gen28 for explanation of ManyToMany mapping.

_________________
Vinod K. Singh


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 23, 2005 4:13 am 
Newbie

Joined: Sat May 21, 2005 6:47 pm
Posts: 3
I have tried using a full syntax with the mapping, but found that i don't need it because the default values work the same way. Same problem with full syntax....

I'm using mysql 4.1.11, hibernate 3.0.3, and annotations preview 1.

Looks like it's just that one query that doesn't work. Simpler queries like getting all contacts, and then getting the groups from the collection objects works fine.

??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 11:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://opensource.atlassian.com/projects/hibernate/browse/HHH-570

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.