title: @ManyToMany Join Table fails
body: <p>I have run into a problem that I haven't been able to solve yet.   </p>
  
  <p>Environment:</p>
  
  <ul>
  <li>MySQL 5</li>
  <li>OS X</li>
  <li>Hibernate 4.1</li>
  <li>Spring 3.1</li>
  <li>Spring Data JPA</li>
  </ul>
  
  <p>I have two entities in a ManyToMany relationship.  I use a Join table with foreign keys for this.
  Here are my entities (modified for brevity):</p>
  
  <pre><code>@Entity
  public class Employee  {
    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private Long employeeId;
  
  @ManyToMany( cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Office.class )
  @JoinTable( name = "EmployeeOfficeJoin", joinColumns = { @JoinColumn( name = "EmployeeId", nullable = false, updatable = false ) }, inverseJoinColumns = { @JoinColumn( name = "OfficeId", nullable = false, updatable = false ) } )
  private List&lt;Office&gt; offices = new ArrayList&lt;Office&gt;();
  }
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>@Entity
  public class Office {
  
  @Id
  @GeneratedValue( strategy = GenerationType.AUTO )
  private Long officeId;
  
  @ManyToMany( mappedBy = "offices", targetEntity = Employee.class, fetch = FetchType.EAGER )
  private List&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();
  </code></pre>
  
  <p>My join table is: </p>
  
  <pre><code>    CREATE  TABLE IF NOT EXISTS `dental`.`EmployeeOfficeJoin` ( 
     `EmployeeId` BIGINT(11) ,
     `OfficeId` BIGINT(11),
     PRIMARY KEY ( `employeeId`, `officeId` ),
     FOREIGN KEY ( `employeeId` ) REFERENCES `Employee` (`EmployeeId` ),
     FOREIGN KEY ( `officeId` ) REFERENCES `Office` ( `Officeid` ) )
  ENGINE = InnoDB
  </code></pre>
  
  <p>I am using this naming:</p>
  
  <pre><code>hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultNamingStrategy
  </code></pre>
  
  <p>when I try to use this:</p>
  
  <pre><code>Employee emp = new Employee();
  ...
  emp.getOffices().add(newOffice);
  employeeRepository.save(emp);
  </code></pre>
  
  <p>the last insert statement before failure is: </p>
  
  <pre><code>Hibernate: 
      insert 
      into
          EmployeeOfficeJoin
          (EmployeeId, OfficeId) 
      values
          (?, ?)
  TRACE - BasicBinder                - binding parameter [1] as [BIGINT] - 1
  TRACE - BasicBinder                - binding parameter [2] as [BIGINT] - 1
  DEBUG - SqlExceptionHelper         - Cannot add or update a child row: a foreign key constraint fails (`dental`.`employeeofficejoin`, CONSTRAINT `employeeofficejoin_ibfk_1` FOREIGN KEY (`EmployeeId`) REFERENCES `Employee` (`EmployeeId`)) [n/a]
  </code></pre>
  
  <p>It appears that the case is all changed, and I see that <a href="http://developmentality.wordpress.com/2011/05/23/hibernate-mysql-mac-foreign-key-nightmares-a-painless-solution-to-a-painful-problem/" rel="nofollow">someone</a> thinks this might be a MySQL on OS X issue.  but when I use</p>
  
  <pre><code>hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
  </code></pre>
  
  <p>that doesn't fix it for me.</p>
  
  <p>So does anyone know if this is a naming strategy issue or something else?</p>