public void saveStat(Statistic stat) { stat.setUpdate(new Date().getTime()); em.getTransaction().begin(); if (stat.getKey() == null) { Calendar cal = Calendar.getInstance(); cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.setTime(stat.getDate()); String key = stat.getMomin() + "$" + stat.getName() + "$" + cal.get(Calendar.YEAR) + "$" + cal.get(Calendar.WEEK_OF_YEAR); stat.setKey(key); em.persist(stat); } else em.merge(stat); em.getTransaction().commit(); }