I never do this, but someone on my project created a many to many relationship between, let’s say, a Foo and a Bar. Foo and Bar both have unique system generated IDs. On Foo, I have the following code:
@ManyToMany(targetEntity = Bar.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "FOO_BAR_LNK",
joinColumns = {@JoinColumn(name = "FOO_ID", referencedColumnName = "ID")},
inverseJoinColumns = {@JoinColumn(name = "BAR_ID", referencedColumnName = "ID")})
private Set<Bar> bars;
When the table gets created, it has 3 columns, HIBERNATE_IDX, FOO_ID and BAR_ID. HIBERNATE_IDX contains all zeroes.
What is HIBERNATE_IDX?
It appears that HIBERNATE_IDX is part of a tie-breaker to guarantee unique indices on join tables and prevent cartesian products. Kind of pieced together, but that’s what I think.