2013-03-01 82 views
0

我想用hibernate从我的数据库的多个表中返回数据。 该查询在我的SQL服务器上正常工作,但它似乎不工作在休眠状态。休眠createSQLQuery JOIN引发异常

Query threadQuery = session.createSQLQuery("SELECT CONCAT(t.lastposter) as lastposter, t.lastpost, t.title, t.threadid, t.lastpostid, t.firstpostid, t.forumid, p.pagetext FROM vbulletin.thread AS t INNER JOIN vbulletin.post AS p ON p.postid = t.firstpostid WHERE t.open != 10 AND t.visible = 1 AND t.forumid != 19 AND t.forumid != 20 ORDER BY t.lastpost DESC").setResultTransformer(Transformers.aliasToBean(VbulletinThread.class)); 

异常

org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 

注:当我从查询中删除p.pagetext它工作正常。

+1

你能尝试'p.pagetext'这应该匹配与'VbulletinThread'领域提供别名。 – 2013-03-01 12:16:44

+0

是的,但没有运气。这将是:SELECT ... t.forumid,p.pagetext AS页面文本从vbulletin.thread ... ORDER BY t.lastpost DESC – Brandon 2013-03-01 13:51:56

回答

0

我想出了问题所在。这与事实无关,我使用了两张桌子。

问题是,我需要在我的SQL查询中转换相应字段的值以使其工作。

所以基本上:

CAST(p.pagetext as char(255)) as pagetext