0

I have Spring MVC Application alongside hibernate. I can cast hql queries to object but the same doesn't apply to SQL. I have the following query to cast to Jpassatempos Object:

List<Jpassatempos> list = (List<Jpassatempos>) 
session.createSQLQuery("select jpassatempos.* from jpassatempos 
left join jcodigos on jpassatempos.Id = jcodigos.PassatemposId 
where jpassatempos.Id in 
     (select jpassatempos_concorrentes.PassatemposId from jpassatempos_concorrentes  
       left join jpassatempos on jpassatempos_concorrentes.PassatemposId = jpassatempos.Id 
       where  jpassatempos_concorrentes.ConcorrentesId = ? and jpassatempos.DataFim > current_date group by jpassatempos_concorrentes.PassatemposId) 
or jpassatempos.Id in 
     (select  jmeuspassatempos.PassatemposId from jmeuspassatempos 
       where ConcorrentesId = ? group by jmeuspassatempos.PassatemposId) 
group by jpassatempos.Id order by sum(jcodigos.NumBolhasRestantes)").setParameter(0, id).setParameter(1, id).list();

Any advice?

1 Answer 1

2

use setResultTransformer( Transformers.aliasToBean(Jpassatempos.class))

Sign up to request clarification or add additional context in comments.

4 Comments

Should i use it like this: Criteria criteria = session.createCriteria(Jpassatempos.class); criteria.setResultTransformer( Transformers.aliasToBean(Jpassatempos.class)); It didn't do anything...
No, createSqlQuery returns a SQLQuery , so it has the method setResultTransformer. createSqlQuery('sql').setParameter().setResultTranformer().list()
Thanks but i get another error: Could not find setter for TipoPassatemposId on class com.setelog.spring.model.Jpassatempos I supose it can't cast correctly because of related entities
try to use addEntity(Jpassatempos.class). ex:...... createSqlQuery('sql').setParameter().addEntity(passatempos.class)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.