Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
Created July 2, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhooke/89f2e10c13dce8a32ed4 to your computer and use it in GitHub Desktop.
Save kevinhooke/89f2e10c13dce8a32ed4 to your computer and use it in GitHub Desktop.
JPA create a copy of existing entity using detach()
ExampleA a = new ExampleA();
em.getTransaction().begin();
em.persist(a);
em.getTransaction().commit();
// ...
em.getTransaction().begin();
em.detach(a);
a.setId(null);
em.persist(a);
em.getTransaction().commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment