Created
July 2, 2015 20:58
-
-
Save kevinhooke/89f2e10c13dce8a32ed4 to your computer and use it in GitHub Desktop.
JPA create a copy of existing entity using detach()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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