-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL: Problem with IN clause
PostPosted: Sun Feb 08, 2009 8:06 pm 
Newbie

Joined: Tue Nov 04, 2008 7:56 pm
Posts: 3
Hi all,

I have the following relevant ejb3 entity beans (i've excluded a lot of code for simplicity so it will probably look incomplete):

User:

@Column(name = "username",
nullable = false,
unique = true)
String username;

@OneToMany(cascade = CascadeType.ALL,
mappedBy = "groupowner",
fetch = FetchType.EAGER)
Set<Group> groups;

@ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.MERGE},
mappedBy = "members",
fetch = FetchType.EAGER)
@JoinTable(name = "user_group_link",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "group_id"))
Set<Group> memberships;

Group:

@ManyToMany(cascade = {CascadeType.REFRESH,
CascadeType.MERGE},
fetch = FetchType.EAGER)
@JoinTable(name = "user_group_link",
joinColumns = @JoinColumn(name = "group_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
private Set<User> members;

--- --- ---

I am trying to execute the following:

String mystmt = "SELECT name FROM Group g WHERE :user IN (g.members)";


Query query = manager.createQuery(mystmt);
query.setParameter("user", myuser);

Hibernate spits this out in my log:

select group0_.name as col_0_0_ from group group0_, user_group_link members1_, user user2_ where group0_.group_id=members1_.group_id and members1_.user_id=user2_.user_id and (? in (.))

Then I get the following errors:

WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: 42601
ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR: syntax error at or near "."
org.postgresql.util.PSQLException: ERROR: syntax error at or near "."

I cannot see why there would be a problem with my HQL.
Can anyone help?

Thanks,
pea


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 7:55 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Hi pea,
There is syntax error in query itself . This query should be like this.

"SELECT g.name FROM Group as g INNER JOIN g.members as m WHERE m = :user"

______________________________________________________
If it helps you, please rate the post.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 6:12 pm 
Newbie

Joined: Tue Nov 04, 2008 7:56 pm
Posts: 3
Thanks so much that worked!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.