用到 lambok 开发工具
notification表
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@ToString(exclude = {"notificationUserMapList"})
@Table(name = "notification")
public class Notification {
@OneToMany(mappedBy = "notification", fetch = FetchType.LAZY, cascade = CascadeType.ALL ,orphanRemoval = false)
private List<NotificationUserMap> notificationUserMapList;
}
notification_user_map 表
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "notification_user_map")
@ToString(exclude = {"notification"})
public class NotificationUserMap {
@ManyToOne
@JoinColumn(name = "notification_id")
private Notification notification;
}
- @ToString(exclude = {"notificationUserMapList"}) 和 @ToString(exclude = {"notification"}) 排除相互的对象 toString
- cascade = CascadeType.ALL ,orphanRemoval = false ,,表明及联操作的性质。
- 双方的对象要相互持有
网友评论