title: how to set ForeignKey name when I have @ManyToMany
body: <p>I'm creating databases using JPA classes.</p>
  <p>If we have <strong>ManyToOne</strong> relation, we can override  ForeignKey name name like this:</p>
  <pre><code>@ManyToOne
  @JoinColumn(foreignKey = @ForeignKey(name = &quot;FK_COUNTRY&quot;))
  private Country country;
  </code></pre>
  <p>In DB, we will have such a result:</p>
  <p><img src="https://i.stack.imgur.com/tcheD.jpg" alt="enter image description here" /></p>
  <p>Ok, that's nice.  good result!</p>
  <p>BUT I will not manage to set my own FK names when I have @ManyToMany.</p>
  <p>How can I create this? I try something like this, but it does not works:</p>
  <pre><code>@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  @JoinTable(name = &quot;NEW_TABLE&quot;,  foreignKey = @ForeignKey(name = &quot;FK_TEST&quot;))
  </code></pre>
  <p>Or something like this:</p>
  <pre><code>@JoinTable(
          name=&quot;NEW_TABLE&quot;,
          joinColumns=
              @JoinColumn(name=&quot;ID1&quot;, referencedColumnName=&quot;ID&quot;,  foreignKey = @ForeignKey(name = &quot;FK_DEV_ID&quot;)),
          inverseJoinColumns=
              @JoinColumn(name=&quot;ID2&quot;, referencedColumnName=&quot;ID&quot;, foreignKey = @ForeignKey(name = &quot;FK_DEV_ZONE&quot;))
      )  
  </code></pre>
  <p>Or this:</p>
  <pre><code>@ManyToMany(cascade = CascadeType.PERSIST)
  @JoinTable(name=&quot;NEW_TABLE_2&quot;,
              joinColumns=
                  @JoinColumn(name=&quot;ID1&quot;, referencedColumnName=&quot;ID&quot;, 
                              foreignKey = @ForeignKey(name = &quot;FK_1&quot;)
                  ),
              inverseJoinColumns=
                  @JoinColumn(name=&quot;ID2&quot;, referencedColumnName=&quot;ID&quot;, 
                              foreignKey = @ForeignKey(name = &quot;FK_2&quot;)
                  ),
              
              foreignKey = @ForeignKey(name = &quot;FK_1&quot;),
              inverseForeignKey = @ForeignKey(name = &quot;FK_2&quot;)
      )  
  
  private List&lt;MyObject&gt; deviceZones;
  </code></pre>
  <p>They does not work.</p>
  <p>I use this version of jars:</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
      &lt;version&gt;4.3.6.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
      &lt;version&gt;4.3.6.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate.common&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
      &lt;version&gt;4.0.5.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
      &lt;version&gt;5.1.2.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
      &lt;version&gt;4.0.6.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>And my java version is 1.8</p>