The
@Stateless
annotation marks the bean as a stateless session bean. In this class, we need to access the Entity bean
Todo
defined earlier. For this we need an
EntityManager
. The
@PersistenceContext
annotation tells the JBoss Server to inject an entity manager during deployment.
@Stateless
public class TodoDao implements TodoDaoInt {
@PersistenceContext
private EntityManager em;
public void persist (Todo todo) {
em.persist (todo);
}
public void delete (Todo todo) {
Todo t = em.merge (todo);
em.remove( t );
}
public void update (Todo todo) {
em.merge (todo);
}
public List <Todo> findTodos () {
return (List <Todo>) em.createQuery("select t from Todo t")
.getResultList();
}
public Todo findTodo (String id) {
return (Todo) em.find(Todo.class, Long.parseLong(id));
}
}