This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

many-to-many bidirectional relationship query

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want to do a bidirectional many-to-many query with HQL but the middle table is a link table. The problem is this is not an object so hibernate is not recognising it and sending back "QueryException in expected: rm" even though it is being used in the query. The mapping is:
<bag name="users" lazy="true" inverse="true" table="RoleMembership">
this has a many-to-many relationship inside it for the User class. The query when changed from objects to tables works perfectly. Are you able to use a link table in an hql query if it is not an object?
Cheers
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Are you able to use a link table in an hql query if it is not an object?


No. HQL works on objects only. If you've mapped the many-to-many corretly though, you shouldn't have to. e.g.:


No I can join like this:

[ September 13, 2006: Message edited by: Paul Sturrock ]
 
russell stoneyroyd
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.
Thing is all I really need to do is a "select count(*)" on the table. Which I'm acessing through a link table that does exist as a Collection but is the wrong object type.
The mapping for the role class users is:

Role membership exists in user but only ever has roles added to it.
From the Role object we want to access the users that have been deleted which is just a simple boolean flag on that user.
Tried using the 2 tables linked together and it didn't work properly.
Not really sure whether I can just use native sql for this one as I only want to return a count of the users.
Cheers
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Not really sure whether I can just use native sql for this one as I only want to return a count of the users


Ultimately you could, but in this case you don't really have to.


Tried using the 2 tables linked together and it didn't work properly.


How did it fail? Any exceptions?
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!