Java.lang.NumberFormatException usando criteria [Resolvido]

1 resposta
Guevara

Oi pessoal!
Estou recebendo este erro:

org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "idImovel"
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Minha lista usando criteria está assim:

public List<Imovel> lista() {
		
		return session.createCriteria(Imovel.class, "i")		
		.setProjection(Projections.projectionList()
				.add( Projections.property("i.idImovel").as("idImovel") )
				.add( Projections.property("i.codImovel").as("codImovel") )
				.add( Projections.property("i.titulo").as("titulo") )
				.add( Projections.property("i.bairro").as("bairro") )
				.add( Projections.property("i.valor").as("valor") )
				.add( Projections.property("i.area").as("area") )
				.add( Projections.property("i.dtInclusao").as("dtInclusao") )
				).addOrder(Order.desc("dtInclusao")).setMaxResults(10).list();		
	}

Alguém sabe o motivo desse erro? A id do imóvel é idImovel mesmo:

@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="id_imovel")
	private Long idImovel;

Abraço!

1 Resposta

Guevara

Faltou uma linha que faz toda a diferença:

public List<Imovel> lista() {
		
		return session.createCriteria(Imovel.class, "i")		
		.setProjection(Projections.projectionList()
				.add( Projections.property("i.idImovel").as("idImovel") )
				.add( Projections.property("i.codImovel").as("codImovel") )
				.add( Projections.property("i.titulo").as("titulo") )
				.add( Projections.property("i.bairro").as("bairro") )
				.add( Projections.property("i.valor").as("valor") )
				.add( Projections.property("i.area").as("area") )
				.add( Projections.property("i.dtInclusao").as("dtInclusao") )
				).setResultTransformer(new AliasToBeanResultTransformer(Imovel.class))
				.addOrder(Order.desc("dtInclusao")).setMaxResults(10).list();
	}

Este é o cara responsável pela conversão dos aliases para Bean.

import org.hibernate.transform.AliasToBeanResultTransformer;

Abraço!

Criado 5 de maio de 2010
Ultima resposta 6 de mai. de 2010
Respostas 1
Participantes 1