无法解析列“account_id”

问题描述 投票:0回答:1

如图,无法设置栏目名称 我使用 Hibernate 6.4.4

我正在尝试在帐户和人员之间创建关系,但收到错误“无法解析列'accound_id'”,我已经完成了映射,但仍然收到上述错误。

<mapping class="com.bravos2k5.models.Account"/>
<mapping class="com.bravos2k5.models.Person"/>

账户类别: @实体 公开课帐号{

@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Getter
@Setter
@Column(nullable = false, unique = true, updatable = false)
private String username;

@Getter
@Setter
@Column(nullable = false)
private String password;

@Getter
@Setter
@Column(unique = true)
private String email;

@Getter
@Setter
@Column(unique = true)
private String phone;

@Getter
@Setter
@OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
private List<Person> personList = new ArrayList<>();

private Boolean isBan;

public void setBan(Boolean isBan) {
    this.isBan = isBan;
}

public Boolean isBan() {
    return isBan;
}

public Account() {}

public Account(String username, String password, String email, String phone, Boolean isBan) {
    this.username = username;
    this.password = password;
    this.email = email;
    this.phone = phone;
    this.isBan = isBan;
}

public Account(String username) {
    this.username = username;
}

}

人物类别:

@Entity
@Getter
@Setter
public class Person {
    public static boolean FEMALE = false;
    public static boolean MALE = true;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;

    private Boolean gender;

    @ManyToOne
    @JoinColumn(name = "account_id") // Problem here
    private Account account;
    
    public Person() {
    
    }
}

请帮我解决这个问题

java hibernate jpa intellij-idea
1个回答
0
投票

答案就在你的问题中:

在您的数据库中,您有一张用于

Person
实例的表。其中每一个都通过人员表中的
Account
列与最多一个
account_id
实例关联。该栏目不存在。

你能做的是:

  • 手动创建列
  • 将迁移添加到潜在的数据库迁移工具(如 Flyway)
  • 使用 hibernates ddl-auto 函数自动为您创建该列
© www.soinside.com 2019 - 2024. All rights reserved.