java 一对多关系 Spring Boot ,错误关系“< xyz>“不存在

wn9m85ua  于 2022-11-20  发布在  Java
关注(0)|答案(2)|浏览(107)

我尝试在Sping Boot 应用程序中创建两个表之间的关系。

@Entity
    @Table(name = "account")
    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public class Account {
      @Id
      @Column(name="ID", nullable = false, updatable = false)
      @GeneratedValue(strategy=GenerationType.SEQUENCE)
      private Long id;
      @Column(name="NAME", nullable = false)
      private String name;
      @Column(name="client_id", nullable = false)
      private Long clientId;
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "client_id", insertable=false, updatable=false)
      private Client client;
    }

    @Entity
    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public class Client {
      @Id
      @Column(name="client_id", nullable = false, updatable = false)
      @GeneratedValue(strategy=GenerationType.SEQUENCE)
      private Long id;
      @Column(name="NAME", nullable = false, unique = true)
      private String name;
      @OneToMany(mappedBy = "client", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
      private List<Account> accounts;
      }

我总是得到错误的关系“帐户”不存在。什么可能是错误的?

Caused by: org.postgresql.util.PSQLException: ERROR: relation "account" does not exist
jqjz2hbq

jqjz2hbq1#

这个异常从数据库返回,转换成java异常,实际上需要确认数据库中存在表account

bcs8qyzn

bcs8qyzn2#

最后,我可以修改它:

spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.hibernate.ddl-auto=update

在application.properties档案中。

相关问题