luckystar +
send mail to luckystar sina weibo
关于订阅 luckystar's blog » Project »
分类:
标签:

1.unexpected token: (

异常信息如下:
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 117 [SELECT t.goodsid,t.shopid,t.goodsname,t.contents,t.remark,p.picurl,m.price,m.gtype,m.total FROM t_goods t left join (select goodsid,picurl from t_picture group by GOODSID) p on p.goodsid = t.goodsid left join t_model m on m.goodsid = t.GOODSID where t.shopid = :shopid and t.status = 1 ORDER BY t.createtime DESC]

sql如下:

SELECT
    t.goodsid,
    t.shopid,
    t.goodsname,
    t.contents,
    t.remark,
    p.picurl,
    m.price,
    m.gtype,
    m.total
FROM
    t_goods t
left join (select goodsid,picurl from t_picture group by GOODSID) p on p.goodsid = t.goodsid
left join t_model m on m.goodsid = t.GOODSID
where t.shopid = :shopid
  and t.status = 1
ORDER BY
    t.createtime DESC;

报这个错,主要是因为我用的Query,非SQLQuery。

Query query = sessionFactory.getCurrentSession().createQuery(sql);

2.No Dialect mapping for JDBC type: -1

出现这个问题的原因是 通过 Hibernate createSQLQuery() 方法进行查询,对应表中的列有 text类型的,方言导致的。
解决方法:自已建一个方言,继承于MySQLDialect ,引入

registerHibernateType(Types.LONGVARCHAR, Hibernate.TEXT.getName());

然后将hibernate注册的方言改成自己的。如:

 
com.unix360.util.BlobMySQLDialect 
 

代码如下:

package com.unix360.util;
import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQLDialect;

public class BlobMySQLDialect extends MySQLDialect {
      public BlobMySQLDialect(){
            super();
            registerHibernateType(Types.LONGVARCHAR, Hibernate.TEXT.getName());
          }

}
作者:qincidong
出处:http://qincidong.github.io/blog/2015/01/13/hibernate-exception.html
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
分类: 标签:
友荐云推荐