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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:20:26+00:00 2026-05-24T09:20:26+00:00

I asked a question here on how to design a database schema. In summary

  • 0

I asked a question here on how to design a database schema.

In summary I have an addressbook that can contain contacts and groups. Groups can also contain contacts, but only contacts which are in the same addressbook as them.

Addressbook

Addressbook id

Contact

id

Addressbook id

Group

id

Group id

Group To Contact

id

Addressbook id

Contact id

Group id

By adding addressbook id to the many to many relationship table, I can enforce that the addressbooks match. I am however relatively new to hibernate, so:

  @Entity
  @Table(name = "Contact")
  public class Contact 
  {
    Addressbook addressbook;

    //----bidirectional association
    private List groups = new ArrayList();
    //----
  }

  @Entity
  @Table(name = "Group")
  public class Group 
  {
    Addressbook addressbook;
    //----bidirectional association
    private List contacts = new ArrayList();
    //----
  }

So at a starting point, I would have the above two tables, and I would need the collections to be controlled by hibernate in a way which would enforce that the addressbook id’s match when adding, or modifying objects within the collection.

  • 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-24T09:20:27+00:00Added an answer on May 24, 2026 at 9:20 am

    You need to specify type of elements in collection and add annotation ManyToMany

      @Entity
      @Table(name = "Contact")
      public class Contact 
      {
    
        @Id
        @GeneratedValue(GenerationType=AUTO)
        private Integer contact_id;
    
        Addressbook addressbook;
    
        //----bidirectional association
        //@ManyToMany
        //private List<Group> groups = new ArrayList<Group>();
        //----
      }
    

    And I think, there is no need to add collection groups to Contact. You can select groups by contact id from Groups table. Also, you need to add id’s to each table.

      @Entity
      @Table(name = "Group")
      public class Group 
      {
        @Id
        @GeneratedValue(GenerationType=AUTO)
        private Integer group_id;
    
        Addressbook addressbook;
        //----bidirectional association
        @ManyToMany
        private List<Contact> contacts = new ArrayList<Contact>();
        //----
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi there I have a short question about database design. I also tried the
Here's a tricky normalization/SQL/Database Design question that has been puzzling us. I hope I
I asked a question here about an Linq error that results from mixing Linq-To-SQL
I have read a lot of gwt-mvp questions that are asked here, but since
I already asked same question here after that i came up with this code
Previously I asked a question here . That problem solved but there are error
I asked the question here and now i would like to reverse this procedure
I asked a question here : When To Use IEquatable And Why about using
I asked a question [ here ] recently and it's just not providing me
Despite an earlier question ( asked here ), our project is constrained to using

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.