Sql server Hibernate将MS SQL server表查询为datetime列的datetime2数据类型

Sql server Hibernate将MS SQL server表查询为datetime列的datetime2数据类型,sql-server,hibernate,spring-boot,jpa,hibernate-mapping,Sql Server,Hibernate,Spring Boot,Jpa,Hibernate Mapping,我在Microsoft SQL Server 2012数据库中有一个表,如下所示 我有一个示例Spring引导应用程序,只是为了测试数据的检索 在实体类中,加入日期表示如下 @Column(name = "joining_date") private Date joiningDate; @Repository public interface EmployeeRepo extends CrudRepository<Employee, Integer> { Employee

我在Microsoft SQL Server 2012数据库中有一个表,如下所示

我有一个示例Spring引导应用程序,只是为了测试数据的检索

在实体类中,加入日期表示如下

@Column(name = "joining_date")
private Date joiningDate;
@Repository
public interface EmployeeRepo extends CrudRepository<Employee, Integer> {
    Employee findByIdAndJoiningDate(Integer id, Date joiningDate);
}
和J假设如下

@Column(name = "joining_date")
private Date joiningDate;
@Repository
public interface EmployeeRepo extends CrudRepository<Employee, Integer> {
    Employee findByIdAndJoiningDate(Integer id, Date joiningDate);
}
当我执行上述测试代码时,我会在SQL profiler中看到datetime2数据类型,其中我的列数据类型是datetime。以下是SQL事件探查器的输出。

declare @p1 int
set @p1=4
exec sp_prepexec @p1 output,N'@P0 int,@P1 datetime2',N'select employee0_.id as id1_0_, employee0_.joining_date as joining_2_0_ from tb_employee employee0_ where employee0_.id=@P0 and employee0_.joining_date=@P1                ',1,'2019-11-25 18:53:48.4870000'
select @p1
如何强制MS SQL作为datetime而不是datetime2执行?

请注意,我也试过写习惯方言。但这没有帮助

public class ModifiedSQLServerDialect extends SQLServer2012Dialect {
    public ModifiedSQLServerDialect () {
        super();
        this.registerColumnType( Types.TIMESTAMP, "datetime" );
    }
}
在application.properties中

spring.jpa.properties.hibernate.dialect: com.example.demo.config.ModifiedSQLServerDialect
非常感谢你的帮助