JPA @ManyToMany @ForeignKey name not used


stephane
 

Hi,
I'm trying to specify foreign-key names. This helps to reduce the effort on db schema comparison at the end of development, to prepare the schema upgrade script.
Actually it works very well on most relationships but I can't find the solution for JoinTables.

Here is an example of User class containing a collection of Group
@JoinTable(name = "iam_user_groups",
joinColumns =@JoinColumn(name = "user_id",referencedColumnName = "id",foreignKey = @ForeignKey(name="fk_user_groups" ))
,inverseJoinColumns = @JoinColumn(name = "group_id",referencedColumnName = "id",foreignKey = @ForeignKey(name="fk_groups_user"))
)
private Set<Group> groups = new HashSet<>();

The SchemaTool and DN doesn't seem to care about the foreignKey = @ForeignKey(name="fk_user_groups" and still generate iam_user_groups_fk1. 

Am I wrong in the mapping definition or is it not yet supported by Datanucleus. (I haven't seen restriction in the JPA specification.)

thanks,
--
Stephane


Andy
 
Edited

You're wrong in the mapping definition. @JoinTable has foreignKey and inverseForeignKey.

Take it up with the people behind JPA why their definition of annotations are unintuitive ... but then you wont find anyone accountable for them, they ran away many years ago.