-->
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.  [ 1 post ] 
Author Message
 Post subject: Query many to many association
PostPosted: Fri Sep 26, 2008 3:08 pm 
Newbie

Joined: Fri Sep 26, 2008 12:55 pm
Posts: 2
Database: MySQL (InnoDB)
Hibernate version:
3.2.6
JDK 1.5

class A{
//
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable( name = "a_b",
joinColumns = {@JoinColumn(name = "a_id")},
inverseJoinColumns = {@JoinColumn(name = "b_id")})
private Set<B> bs = new HashSet<B>();
//
}

class B{
//
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
mappedBy = "bs")
private Set<A> as = new HashSet<A>();
//
}


Now in the dao i am writing a query like this:
// bs is an ArrayList
session.createQuery("from A as a where ((:x) in (a.bs))")
.setParameterList("x", bs)
.list();

I am getting
org.hibernate.exception.SQLGrammarException: could not execute query
......
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You have an error in your SQL syntax;
.......

The SQL generated was

select
a0_.a_id as a1_1_,
a0_.submit_timestamp as submit2_1_,
from
a a0_,
a_b bs1_,
b b2_
where
a0_.a_id=bs1_.a_id
and bs1_.b_id=b2_.b_id
and (
? in (
.
)
)

Cant we query like this? Collection in Collection?


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

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.