嗨,我有 2 个用于 DutyManager 和 DMSchedule 的 pojo 课程
这是我的数据库表详细信息
表名,
Duty_Manager: Manager_ID, Title, Name, Age ,Address PK=Manager_ID
DM_Schedule:Schedule_ID、Manager_ID、From_Date、To_Date PK=Schedule_ID FK=Manager_ID
我应该如何使用休眠注释在 POJO 类级别进行映射。
@Entity
@Table(name = "Duty_Manager")
public class DutyManager {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "my_entity_seq_gen")
@SequenceGenerator(name = "my_entity_seq_gen", sequenceName = "MNG_SEQ")
@Column(name = "MANAGER_ID")
private Long id;
@Column(name = "manager_title", nullable = false)
private String title;
@Column(name = "manager_name", nullable = false)
private String name;
@Column(name = "manager_age", nullable = false)
private int age;
public DutyManager() {
}
//getters and setters
}
@Entity
@Table(name = "DM_Schedule")
public class DM_Schedule {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "my_entity_seq_gen")
@SequenceGenerator(name = "my_entity_seq_gen", sequenceName = "SCH_SEQ")
@Column(name = "Schedule_ID")
private Long id;
@ManyToOne
@JoinColumn(name = "manager_id", nullable = false)
private DutyManager manager;
@Column(name = "date_from", nullable = false)
private Date from;
@Column(name = "date_to", nullable = false)
private Date to;
public DM_Schedule() {
}
//getters and setters
}
编辑:如评论中所述,您还可以Collection<DM_Schedule>
在Manager
课堂上通过注释进行@OneToMany
注释。