Should I let JPA or the database cascade deletions?

前端 未结 3 1717
眼角桃花
眼角桃花 2021-02-05 19:23

Let\'s say we have two entities, A and B. B has a many-to-one relationship to A like follows:

@Entity
public class A {
  @OneToMany(mappedBy="a_id")
  p         


        
3条回答
  •  广开言路
    2021-02-05 20:06

    I'd prefer the database. Why?

    • The database is probably a lot faster doing this
    • The database should be the primary place to hold integrity and relationship information. JPA is just reflecting that information
    • If you're connecting with a different application / platform (i.e. without JPA), you can still cascadingly delete your records, which helps increase data integrity

提交回复
热议问题