Issue Type: Bug Bug
Affects Versions: 4.1.9
Assignee: Unassigned
Created: 16/Feb/13 8:49 AM
Description:

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

Environment: MySQL 5.5, Hibernate 4.1.9
Project: Hibernate ORM
Priority: Major Major
Reporter: Piotr Jagielski
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira