Aaron Diguila answer - the way here, i.e. you need to detach your instances, set the business key to null , and then persist them.
Unfortunately, there is no way to disconnect one object from the entity manager with JPA 1.x (JPA 2.0 will have EntityManager.detach(Object) and fix it). So, either wait for JPA 2.x (not the option I'm assuming) or use the Hibernate underlying Session .
To do this, you can pass the EntityManager delegate to the Hibernate session.
Session session = (Session) em.getDelegate();
Of course, this only works if you use Hibernate as your Java Persistence provider, because the delegate is the Session API.
Then, to detach your object:
session.evict(object);
UPDATE: According to Be careful when using EntityManager.getDelegate () , when using GlassFish you must use (and probably in your case too):
org.hibernate.Session session = ((org.hibernate.ejb.EntityManagerImpl) em.getDelegate()).getSession();
But in JBoss would work not to propose to use the said code previously.
org.hibernate.Session session = (Session) em.getDelegate();
Although I understand that using getDelegate() makes JPA code not portable, I have to admit that I did not expect the result of this method call to be implementation specific.
UPDATE2: In order to answer the updated part of the question, I am not sure that you were looking forward to the categories. This is not the best way to do this, but what happens if you call categories.get(0) before the eviction? In addition, I may miss this part, but where do you collapse the key from the categories?