0

I start my application creating a database model. And I cannot understand if there is any way in hibernate-jpa to save a List of strings as an array.

If I simply try to save my

List<String> someLines;

as sql

some_lines text[]

I get an error that array cannot be represented as a List.

If I put an annotation @ElementCollection like

@ElementCollection
List<String> someLines;

another table some_elements is expected. The same happens If I additionally put an annotation @Column:

@Column(name = "some_lines")
@ElementCollection
List<String> someLines;

How do you usually save a simple List in DB (without creating an additional table)?

youngDev
  • 329
  • 3
  • 16
  • Usually a "list" **is** stored in a separate table - it's the textbook example of normalizing a one-to-many relationship. –  Apr 11 '19 at 08:02
  • No, but you can store an array of strings and some other basic types with an extension you can add to your project dependencies. – coladict Apr 11 '19 at 08:45
  • @a_horse_with_no_name there are different collections. some of them don't need a separate table. good textbooks usually give many different examples. – youngDev Apr 12 '19 at 10:57
  • Take a look at this question: https://stackoverflow.com/q/1647583/1854103 – Tijkijiki Apr 12 '19 at 12:37

0 Answers0