DEV Community

Edgar Rios Navarro
Edgar Rios Navarro

Posted on

Mapping with SCHEMA

Una mala práctica en la configuración de aplicaciones, es usar el owner del esquema para acceder a la base de datos.
Es recomendable crear una cuenta de usuario y otorgar los permisos necesarios y específicos.

Pongamos como ejemplo:

  • ESQUEMA: REGIONALIZACION
  • USUARIO: MSPRODUCTOSWOW
  • PERMISOS:
-- Oracle
GRANT SELECT, INSERT, UPDATE 
ON REGIONALIZACION.LGT_PROD_LOCAL_OFERTA_AUX 
TO MSPRODUCTOSWOW
Enter fullscreen mode Exit fullscreen mode

Empleando las anotaciones de Jakarta Persistence, definimos el mapping de nuestra Entity: name/schema.

import jakarta.persistence.*;

@Table(name = "LGT_PROD_LOCAL_OFERTA_AUX", schema = "REGIONALIZACION")
public record WOWProduct(@EmbeddedId WOWProductId id,
                         float porcDctoOferta,
                         LocalDateTime fecIniVigOferta,
                         LocalDateTime fecFinVigOferta,
                         String usuCreaProdLocOfe,
                         LocalDateTime fecCreaProdLocOfe) {
}
Enter fullscreen mode Exit fullscreen mode

Nótese que podemos usar record, incluso para definir una llave compuesta.

@Embeddable
record WOWProductId(
        @Column(name = "COD_GRUPO_CIA") String codGrupoCia,
        @Column(name = "COD_LOCAL") String codLocal,
        @Column(name = "COD_OFERTA") String codOferta,
        @Column(name = "COD_PROD") String codProd) {
}
Enter fullscreen mode Exit fullscreen mode

Ejecutamos nuestro proyecto basado en #Micronaut:
Image description

Y al listar los productos:
Image description


Documentación

https://micronaut-projects.github.io/micronaut-data/latest/guide/#sqlAnnotations
https://github.com/edgargs/mn-jdbc-schema

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more