Description
I raised this question on Stack overflow:
https://stackoverflow.com/questions/62185317/spring-data-r2dbc-entity-inheritance
in mean time, I've gone trough similar questions and found out that main argument against such feature is mainly that Spring Data R2DBC is not an ORM.
Currently i manage to simulate joined table inheritance with Spring Data R2DBC like following:
@Repository
public class DeviceRepository /*extends ReactiveCrudRepository<DeviceBaseDatabaseModel, Long>*/ {
@Autowired private DatabaseClient databaseClient;
public Mono<Object> save(DeviceBaseDatabaseModel device) {
return databaseClient.insert().into("core_device_base")
.nullValue("id", Long.class)
.value("name", device.getName())
.value("serial_number", device.getSerialNumber())
.value("model_name", device.getModelName())
.value("port_name", device.getPortName())
.value("core_bems_master_id", device.getBemsMasterId())
.map(data -> data).one()
.flatMap(res -> databaseClient.insert().into("core_msf_device")
.value("id", res.get("id"))
.value("pressure", ((MsfDeviceDatabaseModel) device).getPressure())
.value("temperature", ((MsfDeviceDatabaseModel) device).getTemperature())
.value("flow", ((MsfDeviceDatabaseModel) device).getFlow())
.map(data -> data).one()
);
}
}
This becomes repetitive boilerplate code when using over multiple polymorphic types. Spring Data R2DBC already specifies some ORM features like annotations @Table
and @Column
. So it seems that this project is optioned Object Mapper. Spring Data R2DBC is here to give support for relational DB providers and since relational databases are meant to reflect our needs in OO style i suppose many users would appreciate such feature. Is there any reason to not support inheritance at all? Such feature would bring advantages over DB data redundancy, simplifying workflow etc. Also i do not see any "anti-functional" patterns within inheritance support.