No Dialect mapping for JDBC type: -9 with Hibernate 4 and SQL Server 2012

爷,独闯天下 提交于 2019-12-06 11:24:49

This didn't take too much to fix. First, the hibernate.dialect is still:

hibernate.dialect=org.hibernate.dialect.SQLServerDialect

And the ".addScalar" worked, but for Hibernate 4, I had to use the "StandardBasicTypes" class as described below.

    q.addScalar("currency", StandardBasicTypes.STRING);
    q.addScalar("amount", StandardBasicTypes.BIG_DECIMAL);
    q.addScalar("age", StandardBasicTypes.INTEGER);

This was standard to add the parameters:

    q.setParameter("age", age);
    q.setParameter("customerId", customerId);

And finally, I still needed this transformer:

    q.setResultTransformer(Transformers.aliasToBean(MyDTO.class));
    List<MyDTO> results = q.list();

I hope this helps someone else out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!