A second table for simple values, without making them entities.
@Entity
class Order {
@Id Long id;
@ElementCollection
@CollectionTable(name = "order_tags", joinColumns = @JoinColumn(name = "order_id"))
@Column(name = "tag")
Set<String> tags = new HashSet<>();
}
order_tags(order_id, tag)
The rows are owned entirely by the order and deleted with it.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11