• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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!
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic