Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Hibernate (HQL) and many-to-many issues

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the "petclinic" app to learn more about Hibernate and Spring MVC (Hibernate3, and Spring 2.5). It works beautifully, and now I'm customizing/extending this app...


Simply: I have a USER table (tt_user) and a GROUP table (tt_group), and a USERGROUP many-to-many relationship table (tt_usergroup).



I want a list of users that have not yet been added to a given group. Here is the SQL:



My HQL conversion went something like this:




I realized that I may need to have an object to represent the tt_usergroup table, so I created UserGroup. But do I need to? Up until now I haven't needed an explicit object for this table...

Here are my hibernate mappings for User and Group:



At this point, I tried to create a class mapping for the UserGroup object/table:



but that didn't work... it has 2 keys (the only 2 fields in the table...)

Perhaps this approach is wrong?

[ November 07, 2008: Message edited by: Michael Stringham ]
[ November 07, 2008: Message edited by: Michael Stringham ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try

String sql = = "select user from User as user where "+groupID+" not in elements (user.groupsInternal)";

No need to have an object to represent the tt_usergroup table

I found this in the book Harnessing Hibernate. Highly recomended

Cheers,

Luis Casanueva
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic