Using @OrderColumn in many-to-many association results in incorrect primary key generated by hbm2ddl.
Given the following entity:
@Entity(name = "sample_entity") public class SampleEntity { @Id @GeneratedValue() private Integer id; @ManyToMany @JoinTable(name = "entity_relationship", joinColumns = {@JoinColumn(name = "entity_id")}, inverseJoinColumns = {@JoinColumn(name = "relationship_id")}) @OrderColumn(name = "relationship_order") private List<SampleEntity> relationships = new ArrayList<SampleEntity>(); }
Running hbm2ddl results in:
create table entity_relationship ( entity_id integer not null, relationship_id integer not null, relationship_order integer not null, primary key (entity_id, relationship_order) )
The order column becomes a part of primary key. It doesn't make sense. The primary key should consist of join column and inverse join column.
The problem is also described in this blog post: https://forum.hibernate.org/viewtopic.php?uid=81026&f=1&t=1012450&start=0