Using addjoin in Hibernate throws class cast exception
Query
List <t1> t1List = hibernateSession.createSqlQuery
("select * from t1 join t2 on t1.id = t2.id")
.addEntity("t1Alias",t1.class)
.addJoin("j1","t1Alias.id").list();
for(t1 object : t1List ){
log.debug(t1.id); //throws class cast exception
//Cannot convert object to class t1
}
but the same code executes if i remove the addJoin (t1Alias.id)
Can s开发者_运维知识库ome explain why ?
Edit 1:
t1 :t2
N:1See http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html
The <t1>
type parameter isn't necessary when calling hibernateSession.createSqlQuery
(it returns a List
of Object
arrays).Removing it should solve your problems.
精彩评论