Hello
I suppose this is a beginner's question but I have been unable to find the answer on the Internet:
I want to create a new object and related it to already existing objects.
e.g:
Car car = em.createNamedQuery("Car.findById", 1);
Garage garage = new Garage();
garage.setCar(car);
em.persist(garage);
When run, I get the following exception:
Exception in thread "main" javax.persistence.EntityExistsException:
Exception Description: Cannot persist detached object
I understand that the reason here is that I am trying to persist an object that already exists (car).
How do you bypass this?
Thanks in advance.
[Message sent by forum member 'entername' (entername)]
http://forums.java.net/jive/thread.jspa?messageID=260174