PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = null;
try {
ThemeEntity entity = null;
if (id == null) {
entity = new ThemeEntity(name, livingStoryId);
} else {
entity = pm.getObjectById(ThemeEntity.class, id);
entity.setName(name);
}
tx = pm.currentTransaction();
tx.begin();
pm.makePersistent(entity);
tx.commit();
return entity.toClientObject();
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
pm.close();