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 8483601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:09:01+00:00 2026-06-10T20:09:01+00:00

Person.java: public class Person implements java.io.Serializable { private int id; private String fullName; public

  • 0

Person.java:

public class Person  implements java.io.Serializable {
    private int id;
    private String fullName;

    public Person() {
    }

    public Person(int id, String fullName) {
        this.id = id;
        this.fullName = fullName;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

}

ProjectGroup.java:

public class ProjectGroup  implements java.io.Serializable {
    private int id;
    private Set<Person> persons = new HashSet<Person>(0);
    private String name;

    /**
     * Get the value of name
     *
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the value of name
     *
     * @param name new value of name
     */
    public void setName(String name) {
        this.name = name;
    }

    public ProjectGroup() {
    }


    public ProjectGroup(int id, String name, Set<Person> persons) {
       this.id = id;
       this.name = name;
       this.persons = persons;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public Set<Person> getPersons() {
        return this.persons;
    }

    public void setPersons(Set<Person> persons) {
        this.persons = persons;
    }

}

Person.hbm.xml:

<hibernate-mapping>
    <class name="com.mycompany.Person" table="person" schema="public">
        <id name="id" type="int">
            <column name="id" />
            <generator class="identity" />
        </id>

        <property name="fullName" type="string">
            <column name="full_name" length="128" not-null="true" />
        </property>

        <set name="projectGroups" inverse="false" lazy="false" cascade="delete" table="group_person">
            <key>
                <column name="project_id" />
            </key>
            <many-to-many entity-name="com.mycompany.ProjectGroup">
                <column name="group_id" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>

ProjectGroup.hbm.xml:

<hibernate-mapping>
    <class name="com.mycompany.ProjectGroup" table="project_group" schema="public">
        <id name="id" type="int">
            <column name="id" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="name" length="32" not-null="true" />
        </property>
        <set name="persons" inverse="false" table="group_person">
            <key>
                <column name="group_id" />
            </key>
            <many-to-many entity-name="com.mycompany.Person">
                <column name="project_id" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>

What I need to do is load all users with a particular group. I know how to do that with SQL, but the Hibernate equivalent eludes me.

  • 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-06-10T20:09:02+00:00Added an answer on June 10, 2026 at 8:09 pm

    First of all, add to your Person class, property projectGroups declared in your Person.hbn.xml. Afterwards, use this criteria to select all users of certain group:

    Criteria c = session.createCriteria(Person.class);
    c.createAlias("projectGroups", "pg");
    c.add(Restrictions.eq("pg.name", "project-name"));
    

    Or this HQL:

    from Person as person 
        join person.projectGroups as pg 
            with pg.name = 'project-name'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;
import java.util.UUID public class Person implements Serializable { private UUID uuid; public Person() {
heres my test in java public class person { public String name; public int
Given two methods on the same class in Java : public void doSomething( Person
class Person { string name; public Person(string name) { this.name = name; } public
Here is my class: public static class __9_7_Person implements Comparator<__9_7_Person> { private int height;
Person.java public class Person { public String firstName, lastName; public Person(String firstName, String lastName)
Sample XML. <person> <name>Joe Dirt</name> <ssn>123-45-6789</ssn> <dob>07/04/1981</dob> </person> Sample Java Class public class Person(){
I have class Person class person{ int ID ; sting FirstName ; string Last
My code is : ListContacts.java public class ListContacts extends ListActivity { @Override public void

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.