Relation 1-1 in hibernate not working : unknown column account0_.date_of_birth

Unii :

I would like to create 1-1 relation in hiberante but I receive an error:

java.sql.SQLSyntaxErrorException: Unknown column 'account0_.date_of_birth' in 'field list'

User table:

@Entity
@Table(name = "user")
data class User(
        @NonNull
        @Column(nullable = false)
        var login: String,
        @NonNull
        @Column(nullable = false)
        var password: String,
        @NonNull
        @Column(nullable = false)
        var email: String
) {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Int? = 0

    @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = [CascadeType.ALL], orphanRemoval = true)
    @Nullable
    var bloodPressureInformationList: Set<BloodPressureInformation> = HashSet<BloodPressureInformation>()

    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "account_id", referencedColumnName = "id")
    var account: Account? = null

    constructor() : this("", "", "")
}

account table:

@Entity
@Table(name = "account")
data class Account(
        @Column(nullable = false)
        @NonNull
        var firstName: String,
        @Column(nullable = false)
        @NonNull
        var lastName: String,
        @Column(nullable = false)
        @NonNull
        var dateOfBirth: String,
        @Column(nullable = false)
        @Enumerated(EnumType.STRING)
        @NonNull
        var sex: Sex) {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Int? = 0

    @OneToOne(mappedBy = "account", fetch = FetchType.LAZY, optional = false)
    var user: User? = User()
}

Sql migration code:

Create Table user (
id BIGINT NOT NULL AUTO_INCREMENT,
login varchar(50),
password varchar (50),
email varchar(50),
CONSTRAINT user_pk PRIMARY KEY (id)
);

Create Table blood_pressure (
id BIGINT NOT NULL AUTO_INCREMENT,
systolic_pulse INTEGER NOT NULL,
diastolic_pulse INTEGER NOT NULL,
pulse INTEGER,
description varchar(250),
CONSTRAINT blood_pressure_pk PRIMARY KEY (id)
);

ALTER TABLE blood_pressure ADD COLUMN user_id BIGINT NOT NULL DEFAULT 1;
Create Table account (
id BIGINT NOT NULL AUTO_INCREMENT,
firstName varchar(50),
lastName varchar(50),
dateOfBirth varchar(50),
sex varchar(10),
CONSTRAINT account_pk PRIMARY KEY (id)
);
ALTER TABLE user ADD COLUMN account_id BIGINT NOT NULL DEFAULT 1;

Could you tell me how to fix this relation?

InsertKnowledge :

Fix your typo: dateOfBirth varchar(50) should be date_of_birth varchar(50). Same goes for the other camel case columns.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=334340&siteId=1