package com.yammer.stresstime.managers;

import io.dropwizard.hibernate.AbstractDAO;
import org.hibernate.SessionFactory;

public class EntityManager<E> extends AbstractDAO<E> {

    private final Class<? extends E> mEntityClass;

    public EntityManager(SessionFactory sessionFactory, Class<? extends E> entityClass) {
        super(sessionFactory);
        mEntityClass = entityClass;
    }

    public void save(E entity) {
         persist(entity);
    }

    // needs to be a valid entity
    public void delete(E entity) {
        currentSession().delete(entity);
    }

    public E getById(long id) {
        return (E) currentSession().get(mEntityClass, id);
    }

    // issues two queries but deletes only if id exists
    public boolean deleteById(long id) {
        Object persistentInstance = getById(id);
        if (persistentInstance != null) {
            currentSession().delete(persistentInstance);
            return true;
        }
        return false;
    }
}

@@ -563,32 +563,334 @@
 entity);%0A    %7D%0A%0A
+    public boolean safeDelete(E entity) %7B%0A        try %7B%0A            delete(entity);%0A            return true;%0A        %7D catch (Exception e) %7B%0A            /* TODO: Logging to proper stream  */%0A            e.printStackTrace();%0A            return false;%0A        %7D%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A
     public E get

Create safeDelete method in EntityManager