hibernate 执行SQL语句字符串常量类型变成了 character
解决办法
1重写Dialect
public
class
SQLServerDialect
extends
org.hibernate.dialect.SQLServerDialect{
public
SQLServerDialect() {
super
();
//very important, mapping char(n) to String
registerHibernateType(Types.CHAR, Hibernate.STRING.getName());
}
}
2
this.getSession().createSQLQuery("select id,name,state from tb").
addScalar("id", Hibernate.STRING).
addScalar("name", Hibernate.STRING).
addScalar("state", Hibernate.STRING).list();
3
select id,name,cast(state as varchar(2)) from tb