0

I used seam to generate my entities. But I have a many to many composite table with an employee id and a vehicle id and it generated the hash sets wrong. I want to be able to choose an employee's favorite vehicle in the employee object. However; when I add things to the hashset in the employee object and persist it, it does not add anything to the composite table. The vehicle object has the

@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) })

and the employee object has the:

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

I am guessing these are backwards, however; I am new to seam and do not how to switch them around without the mappedBy being all wrong. If anyone knows how to help it would be greatly appreciated. Thank you

user1423793
  • 279
  • 2
  • 6
  • 16

1 Answers1

0

If you want the employee to be the owner of the association, just switch the annotations:

Employee:

@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;

Vehicle:

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "vehicles")
private Set<Employee> employees;
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255