package example.client; import example.entity.UserCredential; import javax.persistence.*; public class Main { // appclient main class must be public // 1. injected field must be static in an appclient. // 2. We can't inject an EntityManager into an appclient, so // let's inject an EntityManagerFactory. @PersistenceUnit private static EntityManagerFactory emf; public static void main(String... args) throws Exception { EntityManager em = emf.createEntityManager(); for(String name : args) { // In ACC, JTA EM is not supported. Let's use EntityTransaction API. EntityTransaction et = em.getTransaction(); et.begin(); System.out.println("Finding " + name); UserCredential uc = em.find(UserCredential.class, name); if(uc!=null) { System.out.println("Found " + name + ", going to remove it"); em.remove(uc); System.out.println("Removed " + name); } else { System.out.println("No user called " + name + ", so creating one."); em.persist(new UserCredential(name, name)); System.out.println("Created " + name); } et.commit(); } em.close(); } }