SpringBoot with hibernate and relationship between postgres tables in different schemas

0

I have the following problem: I created a database named Test and it has two schemas: schema1 and schema2. Within each schema has a table: schema1 - > table1 schema2 - > table2

It turns out that if I try to make a relationship with SpringBoot using annotations between table1 and table2, they do not see each other. with pure sql, with you, just inform the table with schema. schema1.tabela1 schema2.tabela2.

But how do I do this Spring Boot? Here I am.

@Entity @Table(schema = "schema_1") 
public class Tabela1 implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private Integer id;
private String name;
@OneToMany(mappedBy = "tabela1")
private List<Tabela2> tabela2= new ArrayList<>();
publicTabela1() {
    }
 }

second table

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

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String number;
@ManyToOne
@JoinColumn(name = "fk_tabela1")
private Tabela1 tabela1;
public Tabela2() {
         }
     }
    
asked by anonymous 20.07.2018 / 20:06

1 answer

1

In the Table1 class, you may need to map the schema to the Table2 class using the "targetEntity" property:

@OneToMany(targetEntity=Tabela2.class, mappedBy = "tabela1") 
private List tabela2= new ArrayList();
    
20.07.2018 / 23:19