Hibernate MSSQL datetime2 mapping

南楼画角 提交于 2019-12-01 11:33:24

Try registering a new Driver like this:

public class DateTime2SQLServerDialect extends SQLServer2008Dialect {

   public DateTime2SQLServerDialect () {
      super();
      registerColumnType(Types.DATE, "datetime2");
   }
}

and then use this dialect instead:

<property name="hibernate.dialect">my.package.DateTime2SQLServerDialect</property>

Also try changing this:

<return-scalar column="completionTime" type="date" />

to this:

<return-scalar column="completionTime" type="timestamp" />
npn_or_pnp

If you're using entities you can specify the column type as such:

@Column(columnDefinition="datetime2")
private Date completionTime;
I am able to solve above scenario by changing datatype as below,driver registrayion is not required:
<hibernate-mapping>
   <sql-query name="getMLC">
            <return-scalar column="mlcid" type="int" />
            <return-scalar column="completionTime" type="timestamp" />
            { call lsc.MLC_Get(:ABC, :XYZ, :ErrorCode)}
    </sql-query>
</hibernate-mapping>

class Mlc implements java.io.Serializable {

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