Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 623649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:06:56+00:00 2026-05-13T19:06:56+00:00

I have a Group table with ManyToMany relationship with the User table via a

  • 0

I have a Group table with ManyToMany relationship with the User table via a join table. A Group could contain a lot of users or could contain sub groups containing more users.

I am using JPA, Hibernate 3.3

  1. How do I paginate the results returned by Group.getUsers() which could be either users obtained via Group.getUsers OR could be all users from the subgroups in Group.getGroups

Note: Since I have expressed this as a ManyToMany relationship, I don’t have an entity table (for the join table) and not sure how to perform any queries using JPA on the join table.

@Entity
@Table(name = "group")
public class Group {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
    private Integer id;

    @Column(name = "name", length = "255", nullable = false)
    private String name;

    @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JoinTable(name = "group_user", joinColumns = @JoinColumn(name = "group_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
    private List<User> users = new ArrayList<User>(0);

@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "group_subgroup", joinColumns = @JoinColumn(name = "src_group_id"), inverseJoinColumns = @JoinColumn(name = "target_group_id"))
private List<Group> groups = new ArrayList<Group>(0);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:06:56+00:00Added an answer on May 13, 2026 at 7:06 pm

    You can add private List<Group> groups (lazy) in the user entity. And have, for the groups:

    `SELECT u FROM User u JOIN u.groups g WHERE g=:group`
    

    and for the subgroups:

    `SELECT u FROM User u JOIN u.groups WHERE g IN (:groups)`
    

    (and call query.setParameter("groups", group.getGroups()))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a group_names table which stores user groups. Each group has a manager,
I have a M:N relationship between table Users and Groups . Now I am
I have 2 tables with manyToMany relationship. user can have many groups and groups
I have a user table, a user_items table, a user_to_group table and a group
I have five tables: tab_template template_group group user_group user Tab_template's are organized into groups
My problem is, i have a table User and Table Group (this table use
I have 2 Hibernate objects Group and User which are related with a ManyToMany
Say, I have two tables like these: Table group Table user +----+-----------+ +----+----------+------+----------+ |
Today i have new problem with JPA/EJB3. I have 2 table User and Group
I have 2 tables with manyToMany relationship. public class User { public virtual Guid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.