我尝试在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
2条答案
按热度按时间jqjz2hbq1#
这个异常从数据库返回,转换成java异常,实际上需要确认数据库中存在表
account
。bcs8qyzn2#
最后,我可以修改它:
至
在application.properties档案中。