This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Pressing ALT+INSERT in a java SE class generates a method public static void persist(Object object) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("APU"); EntityManager em = emf.createEntityManager(); ...} Calling this method twice will cause a new factory to be created for each persist. With a policy create-and-drop the second persist will effectively destroy the data from the first persist. As you need to create this factory only once I suggest to generate this code as: private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("APU"); public static void persist(Object object) { EntityManager em = emf.createEntityManager(); ...}
yes, it's not the best approach, but static field isn't good too, in my opinion, and anyway lifecycle of EntityManager isn't handled and depends on user requirenment and is likely will require more work. this methd is more like a draft user can rely on. moreover "several invocation", I see no much reason to support it better as all methds do the same if I got it right.
Fair enough, if you don't like the EntityManagerFactory to be static, make it non static, at least it would survive over different persist(Object o) calls. I do not have a problem with EntityManager being created for each persist. Several invocations example: persist(new User("John","Deer")); Persist(new Car("Firebird","V6"); ...
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue. Thanks for your cooperation, NetBeans IDE 8.2 Release Boss