如何在双向关联中使用版本控制Spring数据JPA?

时间:2018-05-22 11:46:46

标签: java spring hibernate java-ee spring-data

假设我在Parent-Child之间具有双向一对多关联,映射如下:

public class TradingAccount {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  @OneToMany(mappedBy = "tradingAccount", cascade = CascadeType.ALL, orphanRemoval = true)
  private List<UnderlyingPerTradingAccount> underlyingPerTradingAccounts;
  @Version
  private Long version;
}

public class UnderlyingPerTradingAccount {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  @ManyToOne
  private TradingAccount tradingAccount;
  private Boolean enableBuy;
  private Boolean enableSell;
}

现在当我更新TradingAccount这个例外时我得到例外:

对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例

0 个答案:

没有答案