通过Hibernate4使用SQL Server2008出现org.hibernate.MappingException
2014-11-19 21:30
375 查看
今天使用Hibernate原生态的SQL语句查询SQL Server2008数据库,出现org.hibernate.MappingException: No Dialect mapping
for JDBC type: -9。
查找-9对应的是NVARCHAR类型。查看Hibernate的SQLServer方言,好像没有类似的注册,那就加一个呗。参考网上资料,可以怎么做:
新建一个类MySQLServerDialect,继承SQLServer2008Dialect,
public class MySQLServerDialect extends SQLServer2008Dialect{
public MySQLServerDialect() {
super();
registerHibernateType(Types.NVARCHAR, Hibernate.STRING.getName());
}
}
但Hibernate类已经没有此STRING常量了,翻找Hibernate的几个包,发现可以registerHibernateType(Types.NVARCHAR,
StringType.INSTANCE.getName());
这样没有报错了。
实际简单点registerHibernateType(Types.NVARCHAR,
"string")也可以啦。
for JDBC type: -9。
查找-9对应的是NVARCHAR类型。查看Hibernate的SQLServer方言,好像没有类似的注册,那就加一个呗。参考网上资料,可以怎么做:
新建一个类MySQLServerDialect,继承SQLServer2008Dialect,
public class MySQLServerDialect extends SQLServer2008Dialect{
public MySQLServerDialect() {
super();
registerHibernateType(Types.NVARCHAR, Hibernate.STRING.getName());
}
}
但Hibernate类已经没有此STRING常量了,翻找Hibernate的几个包,发现可以registerHibernateType(Types.NVARCHAR,
StringType.INSTANCE.getName());
这样没有报错了。
实际简单点registerHibernateType(Types.NVARCHAR,
"string")也可以啦。
相关文章推荐
- 使用hql使用order by子句出现异常和数据异常的解决办法org.hibernate.hql.internal.ast.QuerySyntaxException
- 使用hibernate出现的一个异常org.hibernate.PropertyAccessException: Null value was assigned to a property of pr
- Hibernate4 使用Proxool连接数据库出现 at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer
- 关于使用hibernate出现org.hibernate.LazyInitializationException: could not initialize proxy - no Session错误
- Hibernate通过配置文件构建org.hibernate.Session对象的方式与使用范例源代码
- 在使用hibernate 和spring 构架的框架中如果出现Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm
- 使用 Anotation 注释出现Exception org.hibernate.MappingException: An AnnotationConfiguration。。。
- 使用S2SH框架时,出现org.hibernate.HibernateException: createQuery is not valid without active transaction
- 使用Hibernate出现nested exception is org.hibernate.MappingException: entity class not found:问题
- 使用Hibernate操作,出现org.hibernate.InvalidMappingException: Unable to read XML
- 在intelliJ IDEA下在web项目中使用hibernate出现java.lang.ClassNotFoundException: org.hibernate.criterion.Criteri
- JPA使用多个FetchType.EAGER出现错误Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultan
- Hibernate 使用JUnit 测试出现java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
- myeclipse 使用weblogic10启动hibernate项目时出现ClassNotFoundException: org.hibernate.hql.ast.HqlToken异常的解决办法
- 使用MySQL和Hibernate时,出现java.lang.UnsupportedOperationException: Update queries only supported through HQL异常的解决方法
- 关于Hibernate中fatch=eager的bag集合(一个java List)使用Criteria查询出现重复记录的问题
- 关于使用EJB时出现javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory的问题
- hibernate出现:org.hibernate.PropertyNotFoundException: Could not find a getter for id in class
- 今天用MyEclopse8.5做hibernate测试出现:org.apache.jasper.JasperException: Bad version number in .class file错误
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(三):通过 @Autowired的使用来消除 set ,get方法。