Eclipelink @ElementCollection在合并时删除所有内容

时间:2016-02-01 11:20:28

标签: eclipselink jpa-2.0

我有这个映射:

@Entity
@Table(name="CUSTOMER")
class Customer {

   @Id
   @Column(name="CUSTOMER_ID")
   Long id;

   ...

   @ElementCollection
   @CollectionTable(name="CUSTOMER_ADDRESS", joinColumns=@JoinColumn(name="CUSTOMER_ID"))
   List<CustomerAddress> addresses;

}

@Embeddable
class CustomerAddress {

   String street;
   String zip;
   String ...
   String ...
   ...
}

我有两个已保存的客户ID地址:1。如果我更新此客户,只有一个地址,Eclipselink尝试使用DELETE上的所有CustomerAddress字段删除缺少的地址行where:

DELETE FROM CUSTOMER_ADDRESS WHERE STREET = ?, ..., ZIP = ?, ..., CUSTOMER_ID = ?

问题是我可能有重音和其他数据阻止WHERE语句使用所有字段匹配行。无论如何强制Eclipselink删除所有用户地址并再次插入?

DELETE FROM CUSTOMER_ADDRES WHERE CUSTOMER_ID = ?
INSERT ALL FROM COLLECTION

1 个答案:

答案 0 :(得分:0)

我无法找到实现我想要的方法。看来Hibernate有我期望的行为。

将ElementCollection更改为OneToMany并将模型更改为在CustomerAddress下具有ID。