'JoinTable not generated with @OrderColumn annotation

I think that must work, but seems not. I have an entity, let's call it 'team' that has a list of members where the order is important.

@Table(name = "teams")
public class Team {
    ...

    @OneToMany
    @JoinTable(name = "members_of_team")
    @OrderColumn(name = "index")
    private List<User> members;
}

What I expect for this, is if I set

spring.datasource.jpa.hibernate.ddl-auto=create

The table members_of_team must be generated. But all tables except this one are generated. No error is shown, but I also have a script to populate the database, and when tries to insert data on this table, obviously fails.

The point is, that if I remove @OrderColumn annotation, the table is generated correctly, and the database script is loaded correctly, but probably the order is not assured.

According to this question seems that I am not doing something strange. But for some reasons, seems not working. I am interested in preserving the order of the member list.

The versions I am using are Hibernate 5.4.32.Final, Spring Boot 2.5.5 and MySQL Connector 5.1.49 (with a MySQL 5.7 server).

How can I create the Join Table with order?



Solution 1:[1]

Ok, I have found the issue. The problem is that I am probably not using the best noun on the name of the column in @OrderColumn(name = "index"). Using index is not a good idea and causes the described issue of the question. If I change it to column_index or something else, is working fine and all data is populated correctly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 King Midas