DDL not getting generated for attribute with annotation @ElementCollection

Hi everyone,

I am trying to persist a List using @ElementCollection annotation. When i try to generate database scripts i dont see DDL auto generating for the string table.

Below is the sample code i am using in an entity:

@ElementCollection
@Column(name = "analysisFactors")
@CollectionTable(name = "analysisFactorTable", joinColumns = @JoinColumn(name = "ID"))
protected List<String> analysisFactorList;[AddressTest.zip|attachment](upload://xYdeQMbNXvNOv83T6WaASMtmMNz.zip) (321.3 KB) 

I have attached sample project i am testing.

Cuba Platform Version: 7.0.11

Could you please help me in resolving the issue.

Thank you for the support.

Hi @paddu.bits !
@ElementCollection annotation is not supported on the CUBA platform. You can use the @OneToMany composition in this case.

See docs: https://www.cuba-platform.com/guides/data-modelling-composition?_ga=2.146018420.1935134815.1572333739-471954864.1565853250#one_to_many_composition
Attribute Annotations - CUBA Platform. Developer’s Manual
Attribute Annotations - CUBA Platform. Developer’s Manual

See issue: Support JPA 2.0 embedded collection of user defined class · Issue #295 · cuba-platform/cuba · GitHub

Mmmm.

Okay, so if I want to attach a list of enums to another record, how can this be done without ElementCollection.

WIll I have to create a table holding the enums and associate that with the record instead?

Hi,

You can create an entity with a single enum value. After that add @OneToMany reference of the entity to a main entity.

1 Like