Con Micronaut-Data, tenemosComposeIdout-of-the-box. El manejo es muy similar que JPA.
La tabla de ejemplo contiene una llave primaria formada por dos campos.
CREATETABLE"author_detail_entity"("author_id"BIGINTNOTNULL,"book_id"BIGINTNOTNULL,PRIMARYKEY("author_id","book_id"));
Debemos usar las anotaciones provistas para tal fin:EmbeddedId,Embeddable.
importio.micronaut.data.annotation.*;@MappedEntitypublicclassAuthorDetailEntity{@EmbeddedIdprivateAuthorDetailIdauthorDetailId;publicAuthorDetailEntity(AuthorDetailIdauthorDetailId){this.authorDetailId=authorDetailId;}publicAuthorDetailIdgetAuthorDetailId(){returnauthorDetailId;}}@EmbeddableclassAuthorDetailId{@MappedProperty("author_id")privatefinalLongauthorId;@MappedProperty("book_id")privatefinalLongbookId;publicAuthorDetailId(LongauthorId,LongbookId){this.authorId=authorId;this.bookId=bookId;}publicLonggetAuthorId(){returnauthorId;}publicLonggetBookId(){returnbookId;}}
Extendemos la interface para obtener un CRUD reactivo.
@R2dbcRepository(dialect=Dialect.POSTGRES)publicinterfaceAuthorDetailRepositoryextendsReactiveStreamsCrudRepository<AuthorDetailEntity,AuthorDetailId>{}
Algunos métodos provistos sonfind*,delete*, etc.
Documentación
https://micronaut-projects.github.io/micronaut-data/lates/guide/#sqlCompositeId
https://gitlab.com/edgar.gs/mn-r2dbc.git
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse