title: JPA trying to force me to have a property and database column named 'id'
body: <p>I have a MySQL InnoDB database table with two columns named follower_user_id and followed_user_id, both of which make up the primary key.</p>
  
  <p>I'm trying to map them in Spring Boot but error messages keep telling me I need a property named 'id'. But this table does not have an 'id' column.</p>
  
  <p>What's more, the JPA even autocreates a column named 'id' in the table, definitely not what I want.</p>
  
  <p>Basically when a row gets inserted into this table, the follower_user_id and followed_user_id get provided and the combination form the primary key. There is no autogenerated id.</p>
  
  <p>How do I tell JPA that I don't need a property named 'id', that the forementioned columns make up the primary key and there is no autogenerated key? Thanks!</p>
  
  <pre><code>import java.io.Serializable;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.IdClass;
  
  import org.springframework.data.jpa.domain.AbstractPersistable;
  
  @Entity
  @IdClass(FollowerId.class)
  public class Follower extends AbstractPersistable&lt;Long&gt; implements Serializable {
      private static final long serialVersionUID = 23456789L;
  
      @Id
      private Long followerUserId;
  
      @Id
      private Long followedUserId;
  
      public Long getFollowerUserId() {
          return followerUserId;
      }
  
      public void setFollowerUserId(Long followerUserId) {
          this.followerUserId = followerUserId;
      }
  
      public Long getFollowedUserId() {
          return followerUserId;
      }
  
      public void setFollowedUserId(Long followedUserId) {
          this.followedUserId = followedUserId;
      }
  }
  
  import java.io.Serializable;
  
  public class FollowerId implements Serializable {
      private Long followerUserId;
      private Long followedUserId;
  
      public FollowerId() {
      }
  
      public FollowerId(Long followerUserId, Long followedUserId) {
          this.followerUserId = followerUserId;
          this.followedUserId = followedUserId;
      }
  
      public Long getFollowerUserId() {
          return followerUserId;
      }
  
      public void setFollowerUserId(Long followerUserId) {
          this.followerUserId = followerUserId;
      }
  
      public Long getFollowedUserId() {
          return followerUserId;
      }
  
      public void setFollowedUserId(Long followedUserId) {
          this.followedUserId = followedUserId;
      }
  
      public int hashCode() {
          return (int) (getFollowerUserId() + getFollowedUserId());
      }
  
      public boolean equals(Object obj) {
          if (obj == this) return true;
          if (!(obj instanceof FollowerId)) return false;
          if (obj == null) return false;
          FollowerId pk = (FollowerId) obj;
          return pk.getFollowerUserId() == getFollowerUserId() &amp;&amp; 
              pk.getFollowedUserId() == getFollowedUserId();
      }
  }
  </code></pre>
  
  <p>The error I get:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.PropertyNotFoundException: Unable to locate property named id on com.mightyjava.model.FollowerId
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
      at com.mightyjava.Application.main(Application.java:12) [classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
      at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.2.RELEASE.jar:1.5.2.RELEASE]
  Caused by: org.hibernate.PropertyNotFoundException: Unable to locate property named id on com.mightyjava.model.FollowerId
      at org.hibernate.type.ComponentType.getPropertyIndex(ComponentType.java:740) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.AttributeFactory$3.resolveMember(AttributeFactory.java:973) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.AttributeFactory$5.resolveMember(AttributeFactory.java:1024) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:449) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.AttributeFactory.buildIdAttribute(AttributeFactory.java:128) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.MetadataContext.applyIdMetadata(MetadataContext.java:303) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.MetadataContext.wrapUp(MetadataContext.java:231) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:82) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.internal.EntityManagerFactoryImpl.&lt;init&gt;(EntityManagerFactoryImpl.java:113) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:890) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      ... 21 common frames omitted
  </code></pre>