title: JPA Map ManyToOne Relation with IdClass - persistence.ArgumentException
body: <p>I want to map two classes with a manyToOne /oneToMay relation with Apache OpenJPA 2.2.0.
  One classe has a primary key of two attributes:</p>
  
  <pre><code>@Entity(name = "Player")
  @IdClass(PlayerId.class)
  public class Player {
      @Id
      private String nickname;
      @Id
      @ManyToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name = "team_id")
      private Team team;
  
      public Player() {
  
      }
  
      public String getNickname() {
          return nickname;
      }
  
      public void setNickname(String nickname) {
          this.nickname = nickname;
      }
  
      public Team getTeam() {
          return team;
      }
  
      public void setTeam(Team team) {
          this.team = team;
      }
  
  }
  
  public class PlayerId {
      private String nickname;
      private Team team;
  
      public PlayerId() {
      }
  
      public String getNickname() {
          return nickname;
      }
  
      public void setNickname(String nickname) {
          this.nickname = nickname;
      }
  
      public Team getTeam() {
          return team;
      }
  
      public void setTeam(Team team) {
          this.team = team;
      }
  
      @Override
      public boolean equals(Object o) {
          return ((o instanceof PlayerId) &amp;&amp; 
                  this.nickname == ((PlayerId)o).getNickname() &amp;&amp;
                  this.team == ((PlayerId) o).getTeam());
      }
  
      public int hashCode() {
          return nickname.hashCode() + team.hashCode();
      }
  }
  
  @Entity(name = "Team")
  public class Team {
      @Id
      private String name;
  
      @OneToMany(mappedBy = "team", targetEntity = Player.class, fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
      private List&lt;Player&gt; players;
  
      public Team() {
  
      }
  
      public List&lt;Player&gt; getPlayers() {
          return players;
      }
  
      public void setPlayers(List&lt;Player&gt; p) {
          players = p;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>So When I create a new Player with a team I get the follwing exceptions:</p>
  
  <pre><code>Exception in thread "main" &lt;openjpa-2.2.0-r422266:1244990 fatal user error&gt; org.apache.openjpa.persistence.ArgumentException: Errors encountered while resolving metadata.  See nested exceptions for details.
      at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:668)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:411)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
      at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:714)
      at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:643)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:411)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
      at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:355)
      at org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:682)
      at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:754)
      at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:652)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:154)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:164)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:122)
      at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:209)
      at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
      at main.Main.main(Main.java:27)
  Caused by: &lt;openjpa-2.2.0-r422266:1244990 fatal user error&gt; org.apache.openjpa.persistence.ArgumentException: The id class specified by type "class model.Player" does not match the primary key fields of the class.  Make sure your identity class has the same primary keys as your persistent type, including pk field types. Mismatched property: "team"
      at org.apache.openjpa.meta.ClassMetaData.validateAppIdClassPKs(ClassMetaData.java:2216)
      at org.apache.openjpa.meta.ClassMetaData.validateAppIdClass(ClassMetaData.java:2090)
      at org.apache.openjpa.meta.ClassMetaData.validateIdentity(ClassMetaData.java:2026)
      at org.apache.openjpa.meta.ClassMetaData.validateMeta(ClassMetaData.java:1938)
      at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1799)
      at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:822)
      at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:719)
      at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:643)
      ... 19 more
  NestedThrowables:
  &lt;openjpa-2.2.0-r422266:1244990 fatal user error&gt; org.apache.openjpa.persistence.ArgumentException: Attempt to map "model.Player.team" failed: the owning entity is not mapped.
      at org.apache.openjpa.jdbc.meta.MappingInfo.assertTable(MappingInfo.java:628)
      at org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.java:1079)
      at org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingInfo.java:115)
      at org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingInfo.java:92)
      at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFieldStrategy.java:167)
      at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:146)
      at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:82)
      at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:496)
      at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:461)
      at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:135)
      at org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy.map(RelationCollectionInverseKeyFieldStrategy.java:95)
      at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:146)
      at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:82)
      at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:496)
      at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:461)
      at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:854)
      at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1802)
      at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:822)
      at org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:777)
      at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:657)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:411)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
      at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:714)
      at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:643)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:411)
      at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
      at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:355)
      at org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:682)
      at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:754)
      at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:652)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:154)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:164)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:122)
      at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:209)
      at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
      at main.Main.main(Main.java:27)
  </code></pre>
  
  <p>I know why I get this, but I cant fix it.
  Can someone help me?</p>
  
  <p>There is no problem, when I use a generated primary key (maybe long id) without IdClass.
  But I need the IdClass.</p>
  
  <p>Best Regards
  Veote</p>