Я хотел бы сделать глубокую копию объекта в JPA. Я нашел интересную дискуссию здесь: http://forums.java.net/jive/thread.jspa?messageID=253092&tstart=0
Похоже, предлагаемое решение состояло в том, чтобы установить все @Id на ноль. Вот мой основной код:
//Start a JPA session.
EntityManager em= emf.createEntityManager();
em.getTransaction().begin();
//Get the object I want to copy.
MyClass myObject=em.find(MyClass.class,id);
//Use reflection to find @Id and set them to zero for all @OneToMany and @OneToOne relations.
//TODO: write the ugly recursive code to do this.
//Hoping this will create a deep copy.
em.merge(myObject);
//Close the session.
em.getTransaction().commit();
em.close();
Это хорошая стратегия? Может кто-нибудь уже этот код TODO написал, что они могут делиться???
Спасибо!