2012-06-07 66 views
0

我用seam來生成我的實體。但我有一個許多到許多組合表與一個員工ID和一個車輛ID,它生成的哈希集錯了。我希望能夠在員工對象中選擇員工最喜歡的車輛。然而;當我將東西添加到員工對象中的哈希集並保留它時,它不會向複合表添加任何內容。車輛對象具有mappedBy和joinTable在錯誤的類

@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全部錯誤,不要如何切換它們。如果有人知道如何幫助它將不勝感激。謝謝

回答

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; 
+0

謝謝。它現在有效 – user1423793