SQLServerException:无效的对象名称

问题描述

我用Spring Boot制作了这个小原型,可以在Postgres数据库上正常工作,但是我不得不将其更改为MSsql容器,现在我得到了这个sqlServerException。

这就是我得到的:

每次调用存储库的.getAll()方法时,都会得到一个异常。 我不确定发生了什么,但是我猜hibernate / jpa无法建立与正确表的连接?

飞行路线脚本

CREATE TABLE dbo.StructuralElement
(
    id          INT IDENTITY (1,1) NOT NULL,name        NVARCHAR(128)      NULL,description NVARCHAR(4000)     NULL,-- Could also be NTEXT
    sequel      INT                NOT NULL,-- order within the Hierarchy
    FK_parent   INT                NULL      -- Hierarchy
);

application.properties

server.port=8080

# JPA / Hibernate
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.sqlServer2012Dialect
spring.jpa.generate-ddl=false

#Database Connection
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.sqlServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;database=master
spring.datasource.username=sa
spring.datasource.password=prototype_2020

spring.flyway.schemas=dbo
spring.flyway.locations=classpath:db/migration
spring.flyway.placeholders.schemaName: dbo

实体

@Data
@SuperBuilder
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "StructuralElement")
public class StructuralElement {

    @Id
    private Long id;

    private String name;

    private String description;

    private Long sequel;

存储库

@Repository
public interface PlanstellenRepository extends JpaRepository<Planstelle,Long> {
    
}

这是我的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.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.prototype</groupId>
    <artifactId>userservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>userservice</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>15</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.3.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>15</source>
                    <target>15</target>
                    <release>15</release>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

编辑:已更改为正确的飞行脚本。

解决方法

我通过将表重命名为structural_element来解决了这个问题。 @Table(name="StructuralElement")注释无法正常工作。