• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Retrieving the list of a "join table" in Many-to-Many Mapping using annotations

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello people, I am new to hibernate and its ORM function.

Here is my problem:

I have Users and Groups; 1 User belongs to multiple Groups, and 1 Group can contain multiple users.

I have read many articles and forum threads regarding this issue (e.g. http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=19mappingmanytomanyrelationships).

However, I would like to know if I am able to retrieve a list of the join_table, and use it to display the contents (e.g. ID_USER and ID_GROUPS). Even though, the UserGroup model class doesn't exist.

I have read in some tutorials that a "join table" isn't required if there is no additional columns. However, without a "join table" model class. Is it possible to create and retrieve a List<Join_table> to display its contents?
draw.png
[Thumbnail for draw.png]
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use criteria for retrieving Join table data...
 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shuan

If you realy need to get the data of the join table you can use a native query, it's no neccesary to map the result to an entity or pojo, the result of the query will be a list of array oject, and you can iterate over it to get the result.

Kind regards

César
 
shaun koo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Thanks Caesar. It worked!
 
Cesar Loachamin
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome Dude!
 
Let nothing stop you! Not even this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic