Hello again, here is my situation:
- I create an entity, and save it to the database. This works as expected
- I update the entity, including some data in a joined foreign table
- I call repository.save again, and the data in the foreign table is inserted, but the entity is not updated
The repository has not been customized:
@Repository
interface ShipmentRepository : LcR2dbcRepository<ShipmentEntity, Long>
This is the initial save, which works as expected.
var shipment = ShipmentEntity()
shipment.createdBy = auth.id!!
shipment.name = request.name
shipment.fragile = request.fragile
shipment.weight = request.weight
shipment.length = request.length
shipment.width = request.width
shipment.height = request.height
shipment.storeId = request.storeId.value.toLong()
val shipmentHistory = arrayListOf(ShipmentHistoryEntity())
shipmentHistory[0].shipment = shipment
shipment.history = shipmentHistory
shipment = shipmentRepository.save(shipment).awaitSingle()
For debugging purposes, this is the corresponding SQL statements run by r2dbc (these look good to me):
2022-04-02 04:09:18.307 DEBUG 11312 --- [actor-tcp-nio-1] o.s.r2dbc.core.DefaultDatabaseClient : Executing SQL statement [INSERT INTO shipment (id, name, created_by, customer_id, delivery_image, delivery_image_ext, store_id, fragile, weight, width, length, height, reserved_at, store_location, customer_location) VALUES (NEXTVAL('shipment_id_seq'), $1, $2, $3, NULL, NULL, $4, $5, $6, $7, $8, $9, NULL, NULL, NULL)]
2022-04-02 04:09:18.604 DEBUG 11312 --- [actor-tcp-nio-1] o.s.r2dbc.core.DefaultDatabaseClient : Executing SQL statement [INSERT INTO shipment_history (id, status, updated_at, driver_id, transport_id, shipment_id) VALUES (NEXTVAL('shipment_history_id_seq'), $1, $2, NULL, NULL, $3)]
Then some updates are made to the shipment entity:
shipment.customerId = data.createShipmentUserInfo.toLong()
val storeLocation = addressData.createShipmentAddressInfo.storeLocation
val customerLocation = addressData.createShipmentAddressInfo.customerLocation
shipment.storeLocation =
geometryFactory.createPoint(Coordinate(storeLocation.longitude, storeLocation.latitude))
shipment.customerLocation =
geometryFactory.createPoint(Coordinate(customerLocation.longitude, customerLocation.latitude))
val newHistory = ShipmentHistoryEntity()
newHistory.status = ShipmentStatus.REQUESTED
newHistory.shipment = shipment
shipment.history.add(newHistory)
shipmentRepository.save(shipment).awaitSingle()
I understand that the geometry point updates may be a unique case, however customerId is a simple bigint/long, but that is not updating either. Here is the corresponding SQL:
2022-04-02 04:09:32.218 DEBUG 11312 --- [actor-tcp-nio-2] o.s.r2dbc.core.DefaultDatabaseClient : Executing SQL statement [INSERT INTO shipment_history (id, status, updated_at, driver_id, transport_id, shipment_id) VALUES (NEXTVAL('shipment_history_id_seq'), $1, $2, NULL, NULL, $3)]
As you can see, the new history element is generated, but nothing in shipment is updated, even though customerId, customerLocation, and storeLocation have been updated. Note that I updated the r2dbc driver to org.postgresql:r2dbc-postgresql:0.9.1.RELEASE
, to support the PostGis extension (for the geometry type). Am I doing anything wrong here?