public static TypedQuery<Note> findNotesByAuthorEquals(Worker author) { if (author == null) throw new IllegalArgumentException("The author argument is required"); EntityManager em = Note.entityManager(); TypedQuery<Note> q = em.createQuery( "SELECT o FROM Note AS o WHERE o.author = :author ORDER by o.id DESC", Note.class); q.setParameter("author", author); return q; }
@Transactional public void remove() { if (this.entityManager == null) this.entityManager = entityManager(); if (this.entityManager.contains(this)) { this.entityManager.remove(this); } else { Note attached = Note.findNote(this.id); this.entityManager.remove(attached); } }