• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
shaun koo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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]
 
Haris Tasawar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use criteria for retrieving Join table data...
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hey Thanks Caesar. It worked!
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Dude!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic