开发者

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:1


See 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜