Hibernate version: 3.2.0.cr2
Hibernate Annotations: 3.2.0.CR1
Hibernate Entity Manager: 3.2.0.CR1
JBoss version: 4.0.4.GA
EJB3 version: EJB-3.0 RC8-FD
Name and version of the database you are using: Ingres 3.0.105
The problem is, that I can not use detached objects in the persist method, because this will cause a
org.hibernate.PersistentObjectException: detached entity passed to persist. And I can only call the methods
persist and
merge, because I'm using an EntityManager.
Here is my code example:
Code:
City city = new City();
city.setName("cityName");
Zipcode code = new Zipcode();
code.setCode("myCode");
em.persist(city);
em.persist(code);
Now I want to create a new Address (zipcode and city must not be null in the database!).Code:
Address ad = new Address();
ad.setCity(city); // detached object city
ad.setZipcode(code); // detached object code
Code:
em.persist(ad);
// this will cause the exception and adds no data to the databaseorCode:
em.merge(ad);
// this will work (adds data to the database), but the address object will not get an ID (getId() == null)!