0

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?

Jens Schauder
82.6k35 gold badges198 silver badges379 bronze badges
asked May 14, 2018 at 16:55

1 Answer 1

1

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.

answered May 15, 2018 at 5:54
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Do you have any reference for this on how to achieve this?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.