So, there is that behavior with innodb that can cause problem if some tables lack of primary key.
So with Hibernate, I am looking for a key to specifies a primary key on a @ElementCollection table with a Set as the underling data structure.
I found a way to have a primary key with a map, but it is kind of weird because I do not need a map.
I also found an answer related to @Embeddable, but I do not need that kind of complexities. I am using a Set or Set as the data structure in my entities.
Any idea how to achieve that?
If you use a Set and make the element Column be not null, then hibernate will make a primary key with the join column and element column.
Example:
@Column(name = "STRINGS", nullable = false)
@ElementCollection
private Set<String> strings;
@ElementCollection
cannot take a primary key, because an Embeddable
types cannot have an identifier.
You can add an @OrderColumn
to optimize the generates SQL statements.
If you need a primary key, then you should turn the @ElementCollection
into a @OneToMany
association.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With