Search code examples
javaspring-bootreactive-programmingspring-webfluxr2dbc

What is equivalent for @Formula(used in jpa), in webflux and r2dbc?


I have a firstName and lastName in my database, and I wanna make a fullname variable, I used to set @Formula annotation in hibernate, but as I changed my services to reactive(webflux) and use r2dbc, I can't use it anymore!

my previous code was something like this:

public class OperatorUser implements UserDetails {
    @Id
    @Column(name = "ID")
    private Long id;

    @Column(name = "FIRST_NAME")
    private String firstName;

    @Column(name = "LAST_NAME")
    private String lastName;

    @Column(name = "ADDRESS")
    private String address;

    @Formula("FIRST_NAME || \' \' || LAST_NAME")
    private String fullname; 

Solution

  • @Formula is an Hibernate/JPA annotation and we cannot use it with R2DBC, if we migrate from an hibernate based project to webflux, it's highly recommended to use Hibernate reactive and vert.x to have access to all hibernate annotations and facilities.

    also watching the youtube video in this page help you to understand it clearly.