Mapping schema data base with Data Base in R2DBC

280 Views Asked by At

I'm starting with a Spring Boot + WebFlux + Postgresql project.

It is necessary to carry out the mapping of the bank schema, but in the @Table annotation the schema information is not present, thinking about it I wanted to understand how it would be possible to carry out the mapping for a table contained in a schema.

Table

select id, description from myschema.mytable;

Mapping

package br.com.myschema.example;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table
public class MyTableEntity {

    @Id
    private Long id;

    private String description;
}

How would it be possible to define for the spring-data that I am accessing the owner myschema?

1

There are 1 best solutions below

0
On

Try to execute a initial script using ConnectionFactoryInitializer to select the schema to use.

CREATE SCHEMA IF NOT EXISTS tenant1 ; 
SHOW search_path;
SET search_path  TO tenant1;