0

I've got an legacy database with colums like that: value_1, value_2, value_3...

For a new project I want these columns to one list or an array

@Entity
public class Example {

   @????
   private List<String> values;
   or
   private String[];
}

How should i write the annotations make it work?

I tried it with an custom ValueHandler, but no success. I also can't find any example how to solve the problem or an good example for an custom ValueHandler

1 Answer 1

1
@Column(name = "value_1")
private String value1;

@Column(name = "value_2")
private String value2;

public List<String> getValues() {
    return Arrays.asList(value1, value2);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so can I read the data as List. But if I change something in the List, the data will not send back to the database. Or I'm wrong?
No, it won't. But you can add a setter to your entity and do the symmetric operation: value1 = list.get(0); value2 = list.get(1);.

Your Answer

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.