Reputation: 245
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
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