java – Relate entity to more than one entity


Hi, I have the following entities Customer, Supplier and Financial in my system. All of them have a list of Contacts, as a bidirectional relationship would look like in these molds.

public class Client {
    private List<Contact> contacts

public class Supplier {
    private List<Contatc> contacts

public class Financial {
    private List<Contat> contacts

public class Contact {

I'm using Hibernate as ORM and SpringMVC. Thank you very much in advance.

EDIT: That would be more or less what I need, I found this example and I'm going to study how to use it because I didn't know it, but it seems to solve the problem for me.


Here is an example of bidirectional:

public class User {
    private int     id;
    private String  name;
            name = "groupId")
    private Group   group;
public class Group {
    private int         id;
    private String      name;
    private List<User>  users;

Here's the SOen link I took the example, and there it contains an explanation about the differences between unidirectional and bidirectional;

Scroll to Top