I have an entity with collection of strings. I would like to add a constrains that will check if all items in the collection have size less then 255.
Let's say I have an entity Area
with a collection of references
. I would like to be sure that all references are shorter then 255 characters. Do you know how can I achieve it.
@Entity
@Table(name = "AREA")
public class Area Serializable {
private static final long serialVersionUID = -4756123949793458708L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
private Integer id;
@ElementCollection
@CollectionTable(name = "AREA_REFERENCES", joinColumns = @JoinColumn(name = "AREA_ID"))
@Column(name = "REFERENCE", nullable = false)
@Size(max = 255) // THIS ANNOTATION SEEMS TO NOT WORK
private Set<String> references = new HashSet<>();
....