Reputation: 31
I have a Task
table. It has a foreign key task_status_id
.
I have a TaskStatus
table. It has two primary keys: task_status_id
and lang_id
.
I have a LanguageType
table. It has a primary key lang_id
.
I want to know how to map this relationship in hibernate.
Upvotes: 3
Views: 9701
Reputation: 128919
I think this will probably do what you want:
@Entity
public class Task {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "task_id")
private int id;
@ManyToOne
@JoinColumn(name = "task_status_id")
TaskStatus status;
}
@Entity
public class TaskStatus {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "task_status_id")
private int id;
@ManyToOne
@JoinColumn(name = "lang_id")
LanguageType languageType;
}
@Entity
public class LanguageType {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "lang_id")
private int id;
}
Upvotes: 6