美文网首页
jpa及联操作

jpa及联操作

作者: hk_faith | 来源:发表于2019-09-26 13:58 被阅读0次

用到 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 ,,表明及联操作的性质。
  • 双方的对象要相互持有

相关文章

网友评论

      本文标题:jpa及联操作

      本文链接:https://www.haomeiwen.com/subject/tjzvuctx.html