Hibernate ignores foreign-key attribute name in hbm <many-to-many>

Description

I have the following set:

{{<set name="roles" lazy="false" table="consumer_roles">
<key column="consumer" foreign-key="FKConsumerRolesConsumer"/>
<many-to-many column="role" class="com.example.Role" foreign-key="FKConsumerRolesRole"/>
</set>
}}

In 4.2.11.Final, the foreign key names FKConsumerRolesConsumer and FKConsumerRolesRole are properly honoured, generated [Postgresql]SQL looks like this:

{{alter table consumer_roles add constraint FKConsumerRolesRole foreign key (role) references role;
alter table consumer_roles add constraint FKConsumerRolesConsumer foreign key (consumer) references consumer;}}

In 5.0.2.Final, both names get auto-generated (despite the foreign-key attribute being defined in the hbm.xml definition), it looks like this:

{{alter table consumer_roles add constraint FK48dmxni8c7c85pvwgooneoy92 foreign key (role) references role;
alter table consumer_roles add constraint FKtr3o7se0v5nhgy29tosm9a6ek foreign key (consumer) references consumer;}}

Interesting enough, in 5.0.3.Final, one of the foreign-key definitions worked (see FKConsumerRolesConsumer) but the other one still gets auto-generated.

{{alter table consumer_roles add constraint FK48dmxni8c7c85pvwgooneoy92 foreign key (role) references role;
alter table consumer_roles add constraint FKConsumerRolesConsumer foreign key (consumer) references consumer;}}

Environment

Postresql dialect

Assignee

Andrea Boriero

Reporter

Alejandro Revilla

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Minor
Configure