Relate entity with more than one entity

3

Hello, I have the following Client, Vendor and Financial entities in my system. All of them have a list of Contacts, as would a two-way relationship in these ways.

public class Client {
    @OneToMany
    private List<Contact> contacts
}

public class Supplier {
    @OneToMany
    private List<Contatc> contacts
}

public class Financial {
    @OneToMany
    private List<Contat> contacts
}

public class Contact {
    @ManyToOne
    ?????????
}

I'm using Hibernate as ORM and SpringMVC. Thanks in advance.

EDIT: It would be more or less what I need, I found this example and I'll study how to use it because I did not know it, but it seems to solve the problem.

link

    
asked by anonymous 24.07.2015 / 19:36

1 answer

0

Here is an example of bidirectional:

public class User {
    private int     id;
    private String  name;
    @ManyToOne
    @JoinColumn(
            name = "groupId")
    private Group   group;
}
public class Group {
    private int         id;
    private String      name;
    @OneToMany(mappedBy="group")
    private List<User>  users;
} 

Follow the link of SOen that I took the example, and it contains an explanation of the differences between unidirectional and bidirectional;

    
24.07.2015 / 19:49