JDBC使用外键正确创建实体类吗?

时间:2018-09-02 00:46:45

标签: java mysql spring jdbc

我正在使用sequel pro创建数据库表,如下所示:

表1

https://i.imgur.com/LqIY5aV.png

表2

https://i.imgur.com/RQLm7A2.png

我有一个users表和一个files表。两者之间的共同栏是username

文件

import lombok.Data;

import javax.persistence.*;

@Entity
@Data
public class Files {

    @Id
    @Column(name="fileId")
    private int fileId;

    @JoinColumn(name="ownership")
    private String username;

    @Column(name="fileName")
    private String fileName;

    @Column(name="fileExtension")
    private String fileExtension;
}

用户

import javax.persistence.*;

import lombok.Data;

@Entity
@Data
public class Users {

  @Id
  @Column(name = "username")
  private String user;

  @Column(name = "password")
  private String password;

  @Column(name = "email")
  private String email;

  @Column(name = "premium")
  private int premium;

  @Column(name = "storedBytes")
  private int storedBytes;
}

出现以下错误:

java.sql.SQLSyntaxErrorException: Unknown column 'files0_.file_id' in 'field list'

0 个答案:

没有答案