I have the PessoaDAO class which has the following method:
public List<Pessoa> BuscarTodos() {
List<Pessoa> list = null;
EntityManager em = getEM();
try {
list = em.createQuery("select t from Pessoa t").getResultList();
} catch (HibernateException e) {
System.out.println(e.toString());
} finally {
em.close();
}
return list;
}
And in my Servlet, I have the following doGet:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PessoaDAO<Pessoa> db = new PessoaDAO<Pessoa>();
try {
List<Pessoa> list = db.BuscarTodos();
req.setAttribute("list", list);
getServletContext().getRequestDispatcher("/index.jsp").forward(req, resp);
System.out.println(req.getAttribute("list"));
} catch (Exception e) {
e.printStackTrace();
}
}
Why when I give a sysout, it looks like this:
[model.Pessoa@7d5d4b78, model.Pessoa@1eb15301, model.Pessoa@15f8c5af]
And not the list itself?
If it helps, this is person class:
@Entity
public class Pessoa {
@Id
@GeneratedValue
@Column(name="ID")
private int id;
@Column(name="NOME")
private String nome;
@Column(name="CPF")
private String cpf;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
}