recipients; "> recipients; "> recipients; ">
@Column(name = "recipients", columnDefinition = "text[]", nullable = false)
private List<String> recipients;
This won’t work out-of-the-box with plain JPA, unless you tell Hibernate how to map it.We will give you the three possible solutions.
@ElementCollection
(portable, join table)This works across all databases and stores recipients in a separate table:
@ElementCollection
@CollectionTable(
name = "email_configs_recipients",
joinColumns = @JoinColumn(name = "email_config_id")
)
@Column(name = "recipient", nullable = false)
private List<String> recipients;
👉 Will create a table email_config_recipients
with:
email_config_id
(FK to email_configs
)recipient
(the email string)If you’re using Postgres and want a single column:
@Column(name = "recipients", columnDefinition = "text[]", nullable = false)
@JdbcTypeCode(SqlTypes.ARRAY)
private List<String> recipients;
UserType
in Hibernate 5).text[]
column.jsonb
)If you want max flexibility and don’t need to query individual emails:
@Column(name = "recipients", columnDefinition = "jsonb", nullable = false)
@JdbcTypeCode(SqlTypes.JSON)
private List<String> recipients;
["[email protected]", "[email protected]"]
.