Sahil
Sahil

Reputation: 245

Map single entity field to multiple dB columns in spring data jpa and postgres sql

I have a requirement where I need to map single entity field in the Entity class which can be mapped to any of the three columns of the entity table Ex. private String value_type should be mapped to dB columns value1 or value2 or value3 . In these three whichever field is not null it will be assigned to value_type How can I achieve this using spring data jpa or any annotation?

Upvotes: 0

Views: 137

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81998

You won't be able to do this just with annotations.

One thing that should work is to have value1, value2, and value3 as attributes along with value_type. Make value_type @Transient and without a field. Instead, implement logic in its getters and setter to read and write to the valueX fields.

Upvotes: 1

Related Questions