You don't specify the required database structure backing your mapping. @ElementCollection
relies on a table that is joined up on retrieving the collection.
In Postgresql database for example you are able to store a simple array in within a column which is possible to map. You will need to in include a dependency:
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
</dependency>
And your entity definition will look like:
@Entity
@Table(name = "products")
@TypeDefs(@TypeDef(name = "string-array", typeClass = StringArrayType.class))
public class Product {
@Type(type = "string-array" )
@Column(name = "colours")
private String[] colours;
}
Currently the library only supports ints and strings, but it is a fairly simple task to add new types.