0

I'm new to the reactive programming paradigm, specifically Project Reactor within Spring.

Back in the days when Hibernate was the most used ORM tool, we could use it to automatically create the relationships, such as one-to-many, many-to-many etc. Hibernate would then also create the mediate tables automatically.

From the few I could find on the internet about this subject, I figured a couple things and would like someone to elaborate on them, they are:

  1. Automatic relationships aren't supported under the reactive programming paradigm.
  2. Automatic related tables (x-to-many) creation aren't supported either.

So, if I have a microservice application using Spring WebFlux, Spring Data R2DBC and Postgres, do the relationship tables have to be created manually, as we're out of @OneToMany, @ManyToMany, @JoinColumn, @JoinTable support?

Eg.:

@Data // Lombok
public class Scope {

    @Id
    private long id;
    
    private String name;
    
}

@Data // Lombok
public class Role {

    @Id
    private long id;
    
    private String name;
    
    private Set<Scope> scopes; // <-- here
    
}

Snippets are very welcome.

Yves Calaci
  • 1,019
  • 1
  • 11
  • 37
  • Although you could let Hibernate generate your schema, relying on it from anything other then a test or demo was advised against. It was always the best to manage your schema yourself using things like Flyway or Liqiuibase. – M. Deinum Dec 24 '20 at 18:28
  • Yes, but only many-to-many requires a join table. – K.Nicholas Dec 24 '20 at 18:57
  • I agree to @M.Deinum, a schema migration tool is the best choice for a real application going to production. Read more: https://bootify.io/docs/spring-boot-database-generation-with-hibernate-liquibase.html – Thomas Dec 25 '20 at 11:40

2 Answers2

2

actually the answer is YES. but I recommend you to use Hibernate Reactive. It is like the old Hibernate but reactive. It uses the same methods and annotation names.

I will help you in It's config If you decided to work with the Hibernate Reactive.

Issa Khodadadi
  • 917
  • 7
  • 19
0

Till now Spring Data R2dbc does not support relations between tables. But there still exist some alternative solutions.

  1. Hibernate Reactive bring most JPA features into reactive world, but Spring/Spring Data has no plan to support it, check my article to integrate it into Spring yourself.

  2. Micronaut also include Jdbc/R2dbc modules like Spring Data, but they has complete relations support between tables as JPA, check my Microaunt examples to research it yourself.

Hantsy
  • 8,006
  • 7
  • 64
  • 109