public static void saveLog(String detail) { Log log = new Log(); Person person = MailManagementSystemUI.person; log.setUsername(person.getUsername()); log.setRole(person.getRole().getName()); log.setActionDate(new Date()); log.setDetail(detail); EntityManager entityManager = initialDataLoader.em; if (!entityManager.getTransaction().isActive()) entityManager.getTransaction().begin(); try { entityManager.persist(log); entityManager.getTransaction().commit(); } catch (PersistenceException e) { System.out.println(e.getMessage()); entityManager.getTransaction().rollback(); } }
public void testNonExistentReferenceUsedAsKey() throws Exception { if (usesAnnotatedPOJO()) { // This case is not supported since 4m6, because Hibernate 3.6 does // not support it log.warn("testNonExistentReferenceUsedAsKey() case not supported in JPA version"); return; } createDeliveryType(0, "JUNIT DELIVERY TYPE 0"); execute("CRUD.new"); assertMessage("type=null"); setValue("invoice.year", "2002"); setValue("invoice.number", "1"); assertValue("invoice.date", "1/1/02"); setValue("type.number", "0"); setValue("number", "66"); setValue("description", "JUNIT"); execute("CRUD.save"); assertNoErrors(); setValue("invoice.year", "2002"); setValue("invoice.number", "1"); setValue("type.number", "0"); setValue("number", "66"); execute("CRUD.refresh"); assertNoErrors(); assertValue("description", "JUNIT"); execute("CRUD.refresh"); assertNoErrors(); assertValue("description", "JUNIT"); deleteDeliveryType(0); execute("CRUD.refresh"); assertNoErrors(); assertValue("description", "JUNIT"); execute("CRUD.delete"); assertMessage("Delivery deleted successfully"); }