I'm trying to design a hospitality app. I have two tables as User
and Request
. Users could be Host
or Visitor
and can send host request to each other. but there is no need to define Users as visitor or host, it doesn't matter for the system so I don't have seperate tables for them. This difference is just important in Request table and it's needed to keep visitor_id
and host_id
as foreign keys (mapped with user_id
primary key column from User table because both host and visitor are also User).
My question is how can I define this relation in hibernate with Annotation
? I mean, there should be two foreign keys in Request table and they're mapped to *user_id* primary key column from User table. Every user can be host or visitor many times and makes none or many requests.
@Entity
public class Request {
@Id
private Long req_id;
....
}
See Question&Answers more detail:os