0

我使用 seam 来生成我的实体。但是我有一个多对多的复合表,其中包含一个员工 ID 和一个车辆 ID,它生成了错误的哈希集。我希望能够在员工对象中选择员工最喜欢的车辆。然而; 当我将内容添加到员工对象中的哈希集中并将其持久化时,它不会向复合表中添加任何内容。车辆对象具有

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)  
@JoinTable(name = "flower_store_emp_vehicle", schema = "dbo", catalog = "tyler", joinColumns = { @JoinColumn(name = "vehicle_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "employee_id", nullable = false, updatable = false) })

并且员工对象具有:

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "flowerStoreEmployees")

但是,我猜这些是倒退的;我是接缝新手,不知道如何在没有 mappedBy 完全错误的情况下切换它们。如果有人知道如何提供帮助,将不胜感激。谢谢

4

1 回答 1

0

如果您希望员工成为关联的所有者,只需切换注释:

员工:

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)  
@JoinTable(name = "flower_store_emp_vehicle", 
           schema = "dbo", 
           catalog = "tyler", 
           inverseJoinColumns = { @JoinColumn(name = "vehicle_id", nullable = false, updatable = false) }, 
           joinColumns = { @JoinColumn(name = "employee_id", nullable = false, updatable = false) })
private Set<Vehicle> vehicles;

车辆:

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "vehicles")
private Set<Employee> employees;
于 2012-06-07T17:11:23.857 回答