spring 引导项目和 com.microsoft.sqlserver.jdbc.SQLServerException:不支持 "variant" 数据类型

spring boot project and com.microsoft.sqlserver.jdbc.SQLServerException: The "variant" data type is not supported

使用这个 link - https://dzone.com/articles/configuring-spring-boot-for-microsoft-sql-server

我创建了一个简单的 spring 引导项目以在 MSSQL 版本 13.0.5865.1 中创建 table 并收到以下错误:

2021-03-02 15:01:14.362  INFO 3116 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-03-02 15:01:14.379  INFO 3116 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.SQLServer2012Dialect
2021-03-02 15:01:14.491  WARN 3116 --- [           main] com.zaxxer.hikari.pool.ProxyConnection   : HikariPool-1 - Connection ConnectionID:1 ClientConnectionId: 76d3363d-401a-448d-b7fb-d8b93712c8ef marked as broken because of SQLSTATE(08S01), ErrorCode(0)

com.microsoft.sqlserver.jdbc.SQLServerException: The "variant" data type is not supported.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190) ~[sqljdbc4-4.0.jar:na]
    at com.microsoft.sqlserver.jdbc.TypeInfo$Builder.apply(dtv.java:1996) ~[sqljdbc4-4.0.jar:na]
    at com.microsoft.sqlserver.jdbc.TypeInfo$Builder.build(dtv.java:2158) ~[sqljdbc4-4.0.jar:na]
    at com.microsoft.sqlserver.jdbc.TypeInfo.getInstance(dtv.java:2221) ~[sqljdbc4-4.0.jar:na]

知道问题出在哪里吗?

这是我所有的 classes 和 pom.xml

主要class

package com.termine.mssqldb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MssqldbApplication {

    public static void main(String[] args) {
        SpringApplication.run(MssqldbApplication.class, args);
    }

}

用户class

package com.termine.mssqldb;

import javax.persistence.*;

@Entity
@Table(name = "user_tbl")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

    private Integer id;
    private String name;
    private int age;

    public User() {
    }
    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                ", name='" + name + '\'' +
                ", Age=" + age +
                '}';
    }
}

用户存储库

package com.termine.mssqldb;

import com.termine.mssqldb.User;
import org.springframework.data.repository.CrudRepository;

public interface UserRepository extends CrudRepository<User, Integer> {
    User findByName(String name);
}

应用程序属性


spring.batch.job.enabled=false
spring.main.banner-mode=off
spring.datasource.url=jdbc:sqlserver://localdb:1433;databaseName=localddbname
spring.datasource.username=***
spring.datasource.password=***
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.properties.hibernate.format_sql = true

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServer2012Dialect

debug=true

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.termine</groupId>
    <artifactId>mssqldb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mssqldb</name>
    <description>create table in ms sql</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Spring Boot Connect to Microsoft SQL Server Examples.

为 SQL 服务器 JDBC 驱动程序使用此依赖项定义。

<dependency>
   <groupId>com.microsoft.sqlserver</groupId>
   <artifactId>mssql-jdbc</artifactId>
   <scope>runtime</scope>
</dependency>