public void destroy(Integer id) throws NonexistentEntityException {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Tagrates tagrates;
try {
tagrates = em.getReference(Tagrates.class, id);
tagrates.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The tagrates with id " + id + " no longer exists.", enfe);
}
Coursetag courseTagId = tagrates.getCourseTagId();
if (courseTagId != null) {
courseTagId.getTagratesList().remove(tagrates);
courseTagId = em.merge(courseTagId);
}
em.remove(tagrates);