Uploaded image for project: 'Hibernate ORM'
  1. HHH-10386

In a @ManyToMany assoctiation the @JoinColumn foreignKey is not taken into considertion when generating the association database schema

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.6
    • Fix Version/s: 5.0.7
    • Component/s: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      When declaring a mapping as follows:

      
      @Entity
      @Table(name = "EMPLOYEE")
      public class Employee {
      	@Id
      	@GeneratedValue
      	private Long id;
      
      	@ManyToMany
      	@JoinTable(name = "EMPLOYEE_PROJECT",
      			joinColumns = @JoinColumn(name = "EMPLOYEE_ID", foreignKey = @ForeignKey(name = "FK_EMPLOYEE")),
      			inverseJoinColumns = @JoinColumn(name = "PROJECT_ID", foreignKey = @ForeignKey(name = "FK_PROJECT")))
      	private Set<Project> projects;
      
      }
      
      @Entity
      @Table(name = "PROJECT")
      public class Project {
      	@Id
      	@GeneratedValue
      	private Long id;
      
      	@ManyToMany(mappedBy="projects")
      	private Set<Employee> employees;
      
      }
      

      the generated schema is

      create table EMPLOYEE (id bigint not null, primary key (id))
      
      create table EMPLOYEE_PROJECT (EMPLOYEE_ID bigint not null, PROJECT_ID bigint not null, primary key (EMPLOYEE_ID, PROJECT_ID))
      
      create table PROJECT (id bigint not null, primary key (id))
      
      alter table EMPLOYEE_PROJECT add constraint FKc9v0x49gwfm2m9wal4r6fujq6 foreign key (PROJECT_ID) references PROJECT
      
      alter table EMPLOYEE_PROJECT add constraint FKa9av8l4b215ry58ocy8h646ge foreign key (EMPLOYEE_ID) references EMPLOYEE
      

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                dreab8 Andrea Boriero
                Reporter:
                dreab8 Andrea Boriero
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: