如何在 JPA/Hibernate 中概念化 @OneToMany 映射

How to conceptualize @OneToMany mapping in JPA/Hibernate

我刚开始学习 JPA


我喜欢这样想:

1
2
3
4
5
6
7
8
9
10
11
12
13
@Entity
public class Account {
    // Here I read this as"One Account (The entity we are in) ToMany Transactions (The foreign entity)
    @OneToMany(cascade = CascadeType.ALL)
    private List<Transaction> transactions = new ArrayList<>();
}
@Entity
public class Transaction {
    // If we use the same process as above we get:
    // Many Transactions (The entity we are in) ToOne Account (The foreign entity)
    @ManyToOne
    Account account;
}