title: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
body: <p>I'm trying to configure Spring in the way so that it will inject all the instances of EntityManager class in my project but I'm constantly getting the following error:</p>
  
  <pre><code>Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
  Caused by: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
  </code></pre>
  
  <p>Here are the related configurations in my spring-config.xml</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;context:component-scan base-package="spring.homework"/&gt;
  
  &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="sql.properties"/&gt;
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
          p:driverClassName="${dataSource.driverClassName}"
          p:url="${dataSource.url}"
          p:username="${dataSource.userName}"
          p:password="${dataSource.password}"/&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:dataSource-ref="dataSource"&gt;
      &lt;property name="persistenceProvider"&gt;
          &lt;bean class="org.hibernate.jpa.HibernatePersistenceProvider"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
              p:entityManagerFactory-ref="entityManagerFactory"/&gt;
  </code></pre>
  
  <p>Here are the contents of persistence.xml</p>
  
  <pre><code>    &lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
               version="2.1"&gt;
      &lt;persistence-unit name="default"  transaction-type="JTA"&gt;
          &lt;!--&lt;jta-data-source&gt;java:/DefaultDS&lt;/jta-data-source&gt;--&gt;
          &lt;properties&gt;
              &lt;property name="connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/&gt;
              &lt;property name="hibernate.show_sql" value="false"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>And finally here are the dependencies in pom.xml</p>
  
  <pre><code>&lt;dependencies&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.8.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;4.3.8.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.35&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
          &lt;version&gt;1.8.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
          &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
          &lt;version&gt;1.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.11&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;1.7.2&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>All the similar questions I've found have been resolved by upgrading to JPA 2.1 version but as you can see mine is 2.1. I've tried to clean and install maven a couple of times but that didn't helped. 
  I'm really stuck and I hope somebody can help me.</p>