0

I have a simple Java class which represents a real-life entity I have to store, such as this.

@Data
public class MappingValue {
    private String feature;
    private String value;
}

Now, I want to store several of these mappings as a list in a different entity. This entity is stored in a SQL table, and I want to store these mappings as a list of jsonb objects. I did something like this, but I can't seem to get it to work.

@Column(name = "specifications", columnDefinition = "jsonb")
private List<MappingValue> specifications;

Any ideas? Thanks in advance.

1
  • What does can't seem to get it to work mean? Commented Jun 30, 2020 at 10:30

1 Answer 1

2

You use an JPA Attribute Converter for that. You implement such a Converter to Store a Complex type in one Column of the Db

Example: https://www.baeldung.com/jpa-attribute-converters

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I'm aware of the separate table design. But I want this data in the same table, mostly because it's going to be a very unstructured set of keys and values and I don't necessarily want to force it into a separate table for the heck of it.
Ok then maybe try to implement a Converter like mentioned here: stackoverflow.com/questions/43628222/…, This Converter could make a call to gson or smth like that
Thanks Martin, this helped. Can you add a bit more on your answer about Converters so that I can accept your answer?

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.