3
I have a class, Vendor, which is extended from class Pessoa
.
In the method listarFornecedores
class FOrnecedorDao
:
public List<Fornecedor> listarFornecedores() {
session = HibernateUtil.getSessionFactory().openSession();
List<Fornecedor> listaFornecedores = new ArrayList<Fornecedor>();
query = session.createQuery("FROM Fornecedor");
listaFornecedores = query.list();
session.close();
return listaFornecedores;
}
the result is:
[Person [id=1, name=123, phone=123, address=123, numeroDoEndereco=123, cep=123, bairro=123, cidade=123, estado=123, email=123]]
When rotating the Servlet:
protected void buscar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
List<Fornecedor> listaFornecedores = new FornecedorDao().listarFornecedores();
Integer i = 0;
Fornecedor f = new Fornecedor();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
while ( i < listaFornecedores.size() ) {
f.setid(listaFornecedores.get(i).getid());
f.setInicioAtividades(listaFornecedores.get(i).getInicioAtividades());
String data1 = sdf.format(f.getInicioAtividades());
System.out.println(listaFornecedores);
//System.out.println(data1);
//System.out.println(f.getInicioFormatado());
i=i+1;
}
That is, it only returns the variables of the Person class, and none of the Vendor class... but no jsp is right....
Classe Pessoa:
public abstract class Pessoa implements Serializable{
@Id
@GeneratedValue(strategy= GenerationType.TABLE)
@Column
private Integer id;
@Column
private String nome;
@Column
private String telefone;
@Column
private String endereco;
@Column
private String numeroDoEndereco;
@Column
private String cep;
@Column
private String bairro;
@Column
private String cidade;
@Column
private String estado;
@Column
private String email;
// resto do código omitido
Supplier Class:
public class Fornecedor extends Pessoa{
@Column
private Integer codigo;
@Column
private String pessoaContato;
@Column
private String cnpj;
@Column
private Date inicioAtividades;
/*Getters and Setters*/
}
Can someone give me a light, explain why this happens, and how we should also take the values of the supplier class?
You have placed the Annotations-@Entity @Table(name="Vendor") - in which class?
– Renato Serra
In the Supplier class.
– sounobre
You implemented the method
toString()
in classFornecedor
and wrote it down with@Override
?– Felipe Marinho
Kra, really the problem was in toString()! It was not in the Vendor class, so I added the following in the Vendor class: @Override public String toString() { Super.toString() + "Supplier [code=" + code + ", person Contact=" + person Contact + ", cnpj=" + cnpj + ", homeactivities=" + homeactivities + "]"; }
– sounobre