I am currently trying to implement R2DBC within Spring Boot for an application that is already far into development - meaning, unfortunately, our DDL is not flexible, since other microservices depend on this it and vice versa. One significant limitation of R2DBC is that is does not support nested classes. Moreover, it does not support JPA, since that would would defeat the purpose of being all-around non-blocking. So all those useful annotations are off the table as well.
The class I am dealing with looks something like this:
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Stats {
@Id
StatsPK statsPK
@Column(stat_name)
String stat;
...
@Data
@AllArgsConstructor
@NoArgsConstructor
@Embeddable
public static class StatsPK implements Serializable {
@Column("store_id")
private Integer storeId;
@Column("empl_id")
private String emplId;
@Column("app_version")
private String appVersion;
}
}
After researching my question, I have found many ways to go about accounting for the composite key, including what is already been shown in the example above (using the @Embeddable annotation), using a custom PK object (which is similar, but would have the option of using a class designed for this purpse, such as CompositeKeyHolder), The JPA @TableId(TableId.class) annotation, and some others that seemed less promising.
All of these options seem to either be utilizing JPA or utilizing a nested object, which I cannot do. I can't really think of a way to get around these limitations. But since I'm a beginner, I decided to ask in case anyone has dealt with this issue before. Appreciate any feedback.
Spring Data R2DBCs repository abstraction does not support composite keys yet.
What you could use the DatabaseClient
though to construct your SQL and to query data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With