首页 > 解决方案 > Postgres中不同模式之间的SpringBoot 2 JPA关系

问题描述

需要帮助解决这个问题:我在同一个数据库中有两个不同模式的表:

DB_test schema_1 shema_2

在每个模式中,我都有不同的表:

schema_1 -> 客户端 schema_2 -> 电话。

我的代码

表格1

@Entity @Table(schema = "schema_1") 
public class Client implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
@OneToMany(mappedBy = "client")
private List<Phone> phones = new ArrayList<>();
public PessoaFisica() {
   }
}

表 2

@Entity    
@Table(schema = "schema_2")
public class Phone implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String number;
@ManyToOne
@JoinColumn(name = "fk_client")
private Client client;

public Client() {
   }
}

所以这种关系是行不通的。但是如果这两个表在同一个模式中,它就可以工作。一个模式表应该怎么做才能看到另一个模式的表。

标签: postgresqlspring-bootjpa

解决方案


推荐阅读