Hibernate Envers @ElementCollection on List java

1k views Asked by At

I want to use @ElementCollection on a set of type List, like this:

@ElementCollection
@CollectionTable(name = "MY_PRODUCT", joinColumns = @JoinColumn(name = "ID_PRODUCT"))
private List<MY_PRODUCT> products = new ArrayList<>();

After that, I see Hibernate generates the following script sql:

CREATE TABLE HIST_MY_PRODUCT (
REV number(10,0) not null,
REVTYPE number(3,0) not null,
ID_PRODUCT number(19,0) not null,
PRICE number(10,0),
primary key (REV, REVTYPE, ID_PRODUCT)
);

And if I use a set of type Set, like this:

@ElementCollection
@CollectionTable(name = "MY_PRODUCT", joinColumns = @JoinColumn(name = "ID_PRODUCT"))
private Set<MY_PRODUCT> products = new LinkedHashSet<>();

Hibernate generates the following script sql:

CREATE TABLE HIST_MY_PRODUCT (
REV number(10,0) not null,
REVTYPE number(3,0) not null,
ID_PRODUCT number(19,0) not null,
SETORDINAL number(10,0) not null,
PRICE number(10,0),
primary key (REV, REVTYPE, ID_PRODUCT, SETORDINAL)
);

So, I see the aditional field "SETORDINAL" only for the set of type Set and not for a type List.

Could you explain this case ? I would not change all my List fields to Set.

Thanks in advance for your response.

0

There are 0 answers