0

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.

Aron
  • 1,142
  • 1
  • 14
  • 26
  • Set<> avoids duplicate. So I think hibernate is trying to maintain a column to check for duplicate. – Waqar Jun 04 '15 at 10:27
  • I will try implementing the same. I have referred to http://www.concretepage.com/hibernate/elementcollection_hibernate_annotation – Waqar Jun 04 '15 at 10:57

0 Answers0