Hey guys, what would be the best approach for this process:
public class Customer { private List<Car> carList; ... }
public class Car { private String name; .. }
So have an example Peter bought a ferrari,
Customer peter = new Customer(); Car ferrari = new Car(); car.setName("ferrari") peter.addCar(ferrari); ... (call DB) session.save(peter)
unfortunately he did not like the car (Are u nuts, peter?) so he sold it to Jack. What is the best way to do it?
I could do like: ferrari = getFerrari();
jack = getCustomer(); jack.removeCar(ferrari); (call DB) alterCustomer(jack)
* I just get Jack, remove the car and save it again.
Customer jack = new Customer(); jack.addCar(ferrari); (call DB) session.save(jack)
* and I finally add the same Ferrari to Jack's object and save it.
Is there a easier or better way to do that?
|