嗨我有2个pojo课程用于DutyManager& DMSchedule
这是我的数据库表详情
表名,
Duty_Manager:Manager_ID,标题,名称,年龄,地址PK = Manager_ID
DM_Schedule:Schedule_ID,Manager_ID,From_Date,To_Date PK = Schedule_ID FK = Manager_ID
我应该如何使用hibernate注释在POJO类级别进行映射。
答案 0 :(得分:2)
@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
注释。