架构验证:缺少表中的列[id]

时间:2017-08-13 11:09:08

标签: hibernate jpa spring-data

在我的春季启动应用程序中,我正在尝试将sql-server表映射到实体。

@Entity(name="Employee")
@Table(name = "`Personels`")
public class Employee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="`Id`")
    private Long id;

    @Column(name="`Name`")
    private String name;

    @Column(name="`Surname`")
    private String surname;
...
}

表中的列以大写字母开头,这就是为什么我使用@Column注释,但在错误消息中它表示hibernate找不到列“id”(不是Id)。

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [id] in table [personels]
    at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:85) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

这是我的application.properties文件

spring.datasource.url=jdbc:sqlserver://xxx.xxx.xx.xx;databaseName=xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = validate
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

这是pom:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>com.xxx.yyy.Application</start-class>
        <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>mssql-jdbc</artifactId>
        </dependency>

    </dependencies>

1 个答案:

答案 0 :(得分:0)

通过将我的configuration.yaml文件中的“ hibernate.hbm2ddl.auto:validate”行从“ validate”更改为“ create”来解决此问题,现在看起来像这样:

hibernate.hbm2ddl.auto:create

p.s:如果您打算在运行一次后保留输入对象,则必须将其更改回“ validate”。

这将有助于: Hibernate hbm2ddl.auto possible values and what they do?