H2 数据库列和值不收敛 JAVA Spring

H2 database columns and values don't converge JAVA Spring

我是 java 和 spring 框架的新手,遇到了这个问题。我有 class,它有字段,应该是 H2 中的列。它看起来像这样:

package com.bankapp.bankwebapplication.models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class PersonClient implements Client {
    @Id
    @Column(nullable = false, unique = true)
    private Long id;

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

    @Column(nullable = false)
    private String firstName;

    public String getFirstName() { return firstName; }
    public void setFirstName(String firstName) { this.firstName = firstName; }

    @Column(nullable = false)
    private String lastName;

    public String getLastName() { return lastName; }
    public void setLastName(String lastName) { this.lastName = lastName; }

    @Column(nullable = false)
    private String address;

    public String getAddress() { return address; }
    public void setAddress(String address) { this.address = address; }

    @Column
    private String workPhone;

    public String getWorkPhone() { return workPhone; }
    public void setWorkPhone(String workPhone) { this.workPhone = workPhone; }

    @Column
    private String homePhone;

    public String getHomePhone() { return homePhone; }
    public void setHomePhone(String homePhone) { this.homePhone = homePhone; }

    @Override
    public void getDetails() {

    }
}

此外,我有 data.sql 文件向 table 中插入 1 个值:

INSERT INTO person_client VALUES (1, 'firstName', 'lastName', 'paper street', '+123123', '+321321')

所以,问题是它看起来像这样:

为什么?我该如何解决?

始终 在 INSERT 语句中指定目标列:

INSERT INTO person_client 
  (id, first_name, last_name, address, home_phone, work_phone) 
VALUES 
  (1, 'firstName', 'lastName', 'paper street', '+123123', '+321321')

如果您不指定目标列,值将按位置匹配,并且列的创建顺序显然与您认为的不同。

同意@a_horse_with_no_name,如果您不指定列名,它将根据position/index 插入。你所有的 java 变量都在字符串中,这就是它不抛出任何类转换异常的原因。