OpenJPA
  1. OpenJPA
  2. OPENJPA-1253

JoinColumn annotation not allowed in conjunction with *ToMany annotation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-M1, 2.0.0-M2, 2.0.0-M3
    • Fix Version/s: 2.0.0-M3
    • Component/s: jdbc
    • Labels:
      None

      Description

      I receive the following exception if I have an Entity with a One(Many)ToMany relationship with another Entity.

      <openjpa-2.0.0-SNAPSHOT-r422266:805588 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "....Entity", but this mapping cannot have columns in this context.

      To recreate the failure, add a @JoinColumn annotation to one of the *ToMany relationships in org.apache.openjpa.persistence.jdbc.annotations.AnnoTest1.
      example:
      @MapKey(name = "basic")
      @OneToMany(mappedBy = "oneManyOwner")
      @JoinColumn(name = "asdf")
      protected Map<String, AnnoTest2> inverseOwnerMapKey = new HashMap();

      Then run:
      trunk\openjpa-parent\openjpa-persistence-jdbc>mvn test -Dtest=org.apache.openjpa.persistence.jdbc.annotations.TestOneToMany

        Issue Links

          Activity

          Hide
          Fay Wang added a comment -

          According to JPA 2.0 spec (Section 11.1.21),

          The table in which the JoinColumn annotion is found depends upon the context.
          (1) If the join is for a OneToOne or ManyToOne mapping using a foreign key mapping strategy, the foreign key column is in the table of the source entity or embeddable.

          (2) If the join is for a unidirectional OneToMany mapping using a foreign key mapping strategy, the foreign key is in the table of the target entity.

          (3) If the join is for a ManyToMany mapping or for a one-to-one or bidirectional
          ManyToOne/OneToMany mapping using a join table, the foreign key is in a join table.

          (4) If the join is for an element collection, the foreign key is in a collection table.

          In comparison to the JPA 1.0 spec (Section 9.1.6):
          The table in which it is found depends upon the context.
          (1) If the join is for a OneToOne or Many-ToOne mapping, the foreign key column is in the table of the source entity.

          (2) If the join is for a ManyToMany, the foreign key is in a join table.

          The JoinColumn annotation in v2.0 apparently becomes more flexible as it is allowed to appear for a OneToMany mapping.

          Show
          Fay Wang added a comment - According to JPA 2.0 spec (Section 11.1.21), The table in which the JoinColumn annotion is found depends upon the context. (1) If the join is for a OneToOne or ManyToOne mapping using a foreign key mapping strategy, the foreign key column is in the table of the source entity or embeddable. (2) If the join is for a unidirectional OneToMany mapping using a foreign key mapping strategy, the foreign key is in the table of the target entity. (3) If the join is for a ManyToMany mapping or for a one-to-one or bidirectional ManyToOne/OneToMany mapping using a join table, the foreign key is in a join table. (4) If the join is for an element collection, the foreign key is in a collection table. In comparison to the JPA 1.0 spec (Section 9.1.6): The table in which it is found depends upon the context. (1) If the join is for a OneToOne or Many-ToOne mapping, the foreign key column is in the table of the source entity. (2) If the join is for a ManyToMany, the foreign key is in a join table. The JoinColumn annotation in v2.0 apparently becomes more flexible as it is allowed to appear for a OneToMany mapping.
          Hide
          Fay Wang added a comment - - edited

          JPA 2.0 supports non-default mapping (sec 2.9):

          "In addition, this specification also requires support for the following alternative mapping strategies: the mapping of unidirectional one-to-many relationships by means of foreign key mappings; the mapping of unidirectional and bidirectional one-to-one relationships, bidirectional many-to-one/one-to-many relationships, and unidirectional many-to-one relationships by means of join table mappings. The JoinColumn and JoinTable annotations or corresponding XML elements must be used to specify such non-default mappings. See sections 11.1.21 and 11.1.23."

          For *toMany relation, the non-default and default mappings, according to the spec, are:

          (1) uni-/OneToMany/foreign key strategy
          (2) uni-/OneToMany/join table strategy (default)
          (3) bi-/OneToMany/foreign key strategy (default)
          (4) bi-/OneToMany/join table strategy
          (5) uni-/ManyToMany/join table strategy (default)
          (6) bi-/ManyToMany/join table strategy (default)

          For (1), the spec provides the following example (Sec 11.1.36):
          Example 3: Unidirectional One-to-Many association using a foreign key mapping
          In Customer class:
          @OneToMany(orphanRemoval=true)
          @JoinColumn(name="CUST_ID") // join column is in table for Order
          public Set<Order> getOrders()

          {return orders;}

          For (4), Bi-directional One-to-Many association using the join table mapping
          In Customer class:
          @OneToMany(mappedBy="customer")
          @JoinTable(
          name="Customer_Orders",
          joinColumns=
          @JoinColumn(name="Order_ID", referencedColumnName="ID"),
          inverseJoinColumns=
          @JoinColumn(name="Cust_ID", referencedColumnName="ID")
          )

          public Set<Order> getOrders() {return orders;}

          Note that in this scenario, @JoinTable is required. Simply applying @JoinColumn without @JoinTable will result in an exception thrown by openjpa.

          Similarly for ManyToMany mapping, @JoinTable is required as shown by the example in the spec (11.1.25). Simply applying @JoinColumn will fail with an exception:
          @ManyToMany
          @JoinTable(
          name="CUST_PHONE",
          joinColumns=
          @JoinColumn(name="CUST_ID", referencedColumnName="ID"),
          inverseJoinColumns=
          @JoinColumn(name="PHONE_ID", referencedColumnName="ID")
          )
          public Set<PhoneNumber> getPhones()

          { return phones; }

          The failing example provided in this JIRA is not valid:
          @MapKey(name = "basic")
          @OneToMany(mappedBy = "oneManyOwner")
          @JoinColumn(name = "asdf")
          protected Map<String, AnnoTest2> inverseOwnerMapKey = new HashMap();

          This is a bi-directional OneToMany assocation. If the default foreign key strategy is intended, no JoinColumn annotation should be applied. If the non-default join table strategy is intened, the JoinTable annotation should be applied.

          Show
          Fay Wang added a comment - - edited JPA 2.0 supports non-default mapping (sec 2.9): "In addition, this specification also requires support for the following alternative mapping strategies: the mapping of unidirectional one-to-many relationships by means of foreign key mappings; the mapping of unidirectional and bidirectional one-to-one relationships, bidirectional many-to-one/one-to-many relationships, and unidirectional many-to-one relationships by means of join table mappings. The JoinColumn and JoinTable annotations or corresponding XML elements must be used to specify such non-default mappings. See sections 11.1.21 and 11.1.23." For *toMany relation, the non-default and default mappings, according to the spec, are: (1) uni-/OneToMany/foreign key strategy (2) uni-/OneToMany/join table strategy (default) (3) bi-/OneToMany/foreign key strategy (default) (4) bi-/OneToMany/join table strategy (5) uni-/ManyToMany/join table strategy (default) (6) bi-/ManyToMany/join table strategy (default) For (1), the spec provides the following example (Sec 11.1.36): Example 3: Unidirectional One-to-Many association using a foreign key mapping In Customer class: @OneToMany(orphanRemoval=true) @JoinColumn(name="CUST_ID") // join column is in table for Order public Set<Order> getOrders() {return orders;} For (4), Bi-directional One-to-Many association using the join table mapping In Customer class: @OneToMany(mappedBy="customer") @JoinTable( name="Customer_Orders", joinColumns= @JoinColumn(name="Order_ID", referencedColumnName="ID"), inverseJoinColumns= @JoinColumn(name="Cust_ID", referencedColumnName="ID") ) public Set<Order> getOrders() {return orders;} Note that in this scenario, @JoinTable is required. Simply applying @JoinColumn without @JoinTable will result in an exception thrown by openjpa. Similarly for ManyToMany mapping, @JoinTable is required as shown by the example in the spec (11.1.25). Simply applying @JoinColumn will fail with an exception: @ManyToMany @JoinTable( name="CUST_PHONE", joinColumns= @JoinColumn(name="CUST_ID", referencedColumnName="ID"), inverseJoinColumns= @JoinColumn(name="PHONE_ID", referencedColumnName="ID") ) public Set<PhoneNumber> getPhones() { return phones; } The failing example provided in this JIRA is not valid: @MapKey(name = "basic") @OneToMany(mappedBy = "oneManyOwner") @JoinColumn(name = "asdf") protected Map<String, AnnoTest2> inverseOwnerMapKey = new HashMap(); This is a bi-directional OneToMany assocation. If the default foreign key strategy is intended, no JoinColumn annotation should be applied. If the non-default join table strategy is intened, the JoinTable annotation should be applied.
          Hide
          Fay Wang added a comment - - edited

          Create/Update/Delete/Find for the non-default OneToMany mapping is in r-816795. The findBy operation of the owner side (which has ManyToOne relation) for bi-/OneToMany/foreignKey mapping still fails.

          Show
          Fay Wang added a comment - - edited Create/Update/Delete/Find for the non-default OneToMany mapping is in r-816795. The findBy operation of the owner side (which has ManyToOne relation) for bi-/OneToMany/foreignKey mapping still fails.
          Hide
          Frank Schwarz added a comment -

          > Create/Update/Delete/Find for the non-default OneToMany

          Please also consider this use case:

          Model: Person --> * Address (unidirectional, one-to-many, join-column)
          public class Person

          { @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "PERSON_ID") private List<Address> addresses = new ... }

          Use-case:
          Person p1 = em.find(Person.class, new Long(1));
          Address a = p1.getAddresses.remove(0);
          Person p2 = new Person();
          p2.getAddresses().add(a);
          em.persist(p2)

          Currently it throws:

          2234 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> executing prepstmnt 32053837 SELECT TEST.PERSON_SEQ.NEXTVAL FROM DUAL
          2235 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> [0 ms] spent
          2341 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 19396509> executing prepstmnt 620055 UPDATE TEST.Address SET PERSON_ID = ? WHERE id = ? [params=(null) null, (long) 2]
          2342 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 19396509> [1 ms] spent
          2342 default TRACE [main] openjpa.Runtime - An exception occurred while ending the transaction. This exception will be re-thrown.
          <openjpa-2.0.0-SNAPSHOT-r422266:816795 fatal store error> org.apache.openjpa.util.StoreException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.
          at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2249)
          at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2096)
          at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1994)
          at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1912)
          at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
          at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1436)
          at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:895)
          at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:557)
          at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.shuffle(OneToManyUnidirectionalJoinColumnMain.java:157)
          at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.main(OneToManyUnidirectionalJoinColumnMain.java:59)
          Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:816795 fatal user error> org.apache.openjpa.util.InvalidStateException: Attempt to set column "Address.PERSON_ID" to two different values: (null)"null", (class java.lang.Long)"2" This can occur when you fail to set both sides of a two-sided relation between objects, or when you map different fields to the same column, but you do not keep the values of these fields in synch.
          at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:344)
          at org.apache.openjpa.jdbc.sql.RowImpl.flushJoinValues(RowImpl.java:289)
          at org.apache.openjpa.jdbc.sql.RowImpl.flushForeignKey(RowImpl.java:222)
          at org.apache.openjpa.jdbc.sql.RowImpl.setForeignKey(RowImpl.java:197)
          at org.apache.openjpa.jdbc.sql.PrimaryRow.setForeignKey(PrimaryRow.java:172)
          at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.updateInverse(RelationToManyInverseKeyFieldStrategy.java:334)
          at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(RelationToManyInverseKeyFieldStrategy.java:204)
          at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(RelationToManyInverseKeyFieldStrategy.java:190)
          at org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:608)
          at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:230)
          at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:162)
          at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:95)
          at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
          at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:677)
          at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
          ... 9 more

          Persisting the p2-object before transferring the address-object or issuing a em.flush() before transferring the address-object will not bring up the error.

          Show
          Frank Schwarz added a comment - > Create/Update/Delete/Find for the non-default OneToMany Please also consider this use case: Model: Person --> * Address (unidirectional, one-to-many, join-column) public class Person { @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "PERSON_ID") private List<Address> addresses = new ... } Use-case: Person p1 = em.find(Person.class, new Long(1)); Address a = p1.getAddresses.remove(0); Person p2 = new Person(); p2.getAddresses().add(a); em.persist(p2) Currently it throws: 2234 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> executing prepstmnt 32053837 SELECT TEST.PERSON_SEQ.NEXTVAL FROM DUAL 2235 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> [0 ms] spent 2341 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 19396509> executing prepstmnt 620055 UPDATE TEST.Address SET PERSON_ID = ? WHERE id = ? [params=(null) null, (long) 2] 2342 default TRACE [main] openjpa.jdbc.SQL - <t 13101223, conn 19396509> [1 ms] spent 2342 default TRACE [main] openjpa.Runtime - An exception occurred while ending the transaction. This exception will be re-thrown. <openjpa-2.0.0-SNAPSHOT-r422266:816795 fatal store error> org.apache.openjpa.util.StoreException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2249) at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2096) at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1994) at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1912) at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81) at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1436) at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:895) at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:557) at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.shuffle(OneToManyUnidirectionalJoinColumnMain.java:157) at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.main(OneToManyUnidirectionalJoinColumnMain.java:59) Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:816795 fatal user error> org.apache.openjpa.util.InvalidStateException: Attempt to set column "Address.PERSON_ID" to two different values: (null)"null", (class java.lang.Long)"2" This can occur when you fail to set both sides of a two-sided relation between objects, or when you map different fields to the same column, but you do not keep the values of these fields in synch. at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:344) at org.apache.openjpa.jdbc.sql.RowImpl.flushJoinValues(RowImpl.java:289) at org.apache.openjpa.jdbc.sql.RowImpl.flushForeignKey(RowImpl.java:222) at org.apache.openjpa.jdbc.sql.RowImpl.setForeignKey(RowImpl.java:197) at org.apache.openjpa.jdbc.sql.PrimaryRow.setForeignKey(PrimaryRow.java:172) at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.updateInverse(RelationToManyInverseKeyFieldStrategy.java:334) at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(RelationToManyInverseKeyFieldStrategy.java:204) at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(RelationToManyInverseKeyFieldStrategy.java:190) at org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:608) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:230) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:162) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:95) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:677) at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130) ... 9 more Persisting the p2-object before transferring the address-object or issuing a em.flush() before transferring the address-object will not bring up the error.
          Hide
          Fay Wang added a comment -

          Frank, Thank you for your comment. Your example shows a uni-directional one-to-many using foreign key strategy. I will take a look at this problem.

          Show
          Fay Wang added a comment - Frank, Thank you for your comment. Your example shows a uni-directional one-to-many using foreign key strategy. I will take a look at this problem.
          Hide
          Fay Wang added a comment -

          The fix for the exception reported by Frank is checked into openjpa-trunk r-817399.

          Show
          Fay Wang added a comment - The fix for the exception reported by Frank is checked into openjpa-trunk r-817399.
          Hide
          Jimmy Isaac Ventura Salcedo added a comment -

          Is there an equivalent fix for version 1.2.1? i have encountered the same issue there.

          Example:

          public class BaseLog

          { @OneToMany(fetch=EAGER) @JoinColumn(name="PROVIDER_ID", referencedColumnName="CODIGOMICO") private Set<RufteEnte> rufteEnte; .... }

          public class RufteEnte implements Serializable

          { private static final long serialVersionUID = 1L; @Id private long id; private String codigomico; ... }

          java.lang.AssertionError: Exception:<openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "org.venture.jpa.BaseLog.rufteEnte", but this mapping cannot have columns in this context.
          at org.junit.Assert.fail(Assert.java:91)
          at org.venture.jpa.TestBaseLogDAO.testGetBaseLog(TestBaseLogDAO.java:17)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
          at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
          at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
          at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
          at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
          at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
          at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

          Show
          Jimmy Isaac Ventura Salcedo added a comment - Is there an equivalent fix for version 1.2.1? i have encountered the same issue there. Example: public class BaseLog { @OneToMany(fetch=EAGER) @JoinColumn(name="PROVIDER_ID", referencedColumnName="CODIGOMICO") private Set<RufteEnte> rufteEnte; .... } public class RufteEnte implements Serializable { private static final long serialVersionUID = 1L; @Id private long id; private String codigomico; ... } java.lang.AssertionError: Exception:<openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "org.venture.jpa.BaseLog.rufteEnte", but this mapping cannot have columns in this context. at org.junit.Assert.fail(Assert.java:91) at org.venture.jpa.TestBaseLogDAO.testGetBaseLog(TestBaseLogDAO.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41) at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.ParentRunner.run(ParentRunner.java:220) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
          Hide
          Maarten Van Puymbroeck added a comment -

          Jimmy,

          I believe there is no fix for versions 1.* because the JPA 1.0 standard does not seem to support JoinColumn on a OneToMany. (See Fay Wang's initial comment).

          I also have this problem because I have moved from another JPA implementation that does support this, but that is against the standard.

          Show
          Maarten Van Puymbroeck added a comment - Jimmy, I believe there is no fix for versions 1.* because the JPA 1.0 standard does not seem to support JoinColumn on a OneToMany. (See Fay Wang's initial comment). I also have this problem because I have moved from another JPA implementation that does support this, but that is against the standard.
          Hide
          Derya Altuntas added a comment -

          I am using open JPA 2.1.0 .I am receiving same error
          <openjpa-2.1.0-r422266:1071316 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "com.siemens.EntityBean.DBAccessManager.Role.authorizations", but this mapping cannot have columns in this context.
          at org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInfo.java:382)
          at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:120)
          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:1801)
          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.enhance.PCEnhancer.<init>(PCEnhancer.java:283)
          at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:254)
          at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:222)
          at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:134)
          at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:315)
          at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:239)
          at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:213)
          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 org.jboss.jpa.deployment.ManagedEntityManagerFactory.getNonTxEntityManager(ManagedEntityManagerFactory.java:72)
          at org.jboss.jpa.deployment.ManagedEntityManagerFactory.getTransactionScopedEntityManager(ManagedEntityManagerFactory.java:171)
          at org.jboss.jpa.deployment.PersistenceUnitDeployment.getTransactionScopedEntityManager(PersistenceUnitDeployment.java:178)
          at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:262)
          at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:191)
          at com.siemens.EntityBean.DBAccessManager.UserService.find(UserService.java:22)
          at com.siemens.SessionBean.FileManager.FileManagerBean.printUsers(FileManagerBean.java:86)
          at com.siemens.SessionBean.FileManager.FileManagerBean.copyFile(FileManagerBean.java:43)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          Show
          Derya Altuntas added a comment - I am using open JPA 2.1.0 .I am receiving same error <openjpa-2.1.0-r422266:1071316 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "com.siemens.EntityBean.DBAccessManager.Role.authorizations", but this mapping cannot have columns in this context. at org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInfo.java:382) at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:120) 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:1801) 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.enhance.PCEnhancer.<init>(PCEnhancer.java:283) at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:254) at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:222) at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:134) at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:315) at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:239) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:213) 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 org.jboss.jpa.deployment.ManagedEntityManagerFactory.getNonTxEntityManager(ManagedEntityManagerFactory.java:72) at org.jboss.jpa.deployment.ManagedEntityManagerFactory.getTransactionScopedEntityManager(ManagedEntityManagerFactory.java:171) at org.jboss.jpa.deployment.PersistenceUnitDeployment.getTransactionScopedEntityManager(PersistenceUnitDeployment.java:178) at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:262) at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:191) at com.siemens.EntityBean.DBAccessManager.UserService.find(UserService.java:22) at com.siemens.SessionBean.FileManager.FileManagerBean.printUsers(FileManagerBean.java:86) at com.siemens.SessionBean.FileManager.FileManagerBean.copyFile(FileManagerBean.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          Hide
          Derya Altuntas added a comment -

          I am using open JPA 2.1.0 .I am receiving same error
          <openjpa-2.1.0-r422266:1071316 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "com.siemens.EntityBean.DBAccessManager.Role.authorizations", but this mapping cannot have columns in this context.
          at org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInfo.java:382)
          at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:120)
          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:1801)
          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.enhance.PCEnhancer.<init>(PCEnhancer.java:283)
          at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:254)
          at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:222)
          at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:134)
          at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:315)
          at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:239)
          at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:213)
          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 org.jboss.jpa.deployment.ManagedEntityManagerFactory.getNonTxEntityManager(ManagedEntityManagerFactory.java:72)
          at org.jboss.jpa.deployment.ManagedEntityManagerFactory.getTransactionScopedEntityManager(ManagedEntityManagerFactory.java:171)
          at org.jboss.jpa.deployment.PersistenceUnitDeployment.getTransactionScopedEntityManager(PersistenceUnitDeployment.java:178)
          at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:262)
          at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:191)
          at com.siemens.EntityBean.DBAccessManager.UserService.find(UserService.java:22)
          at com.siemens.SessionBean.FileManager.FileManagerBean.printUsers(FileManagerBean.java:86)
          at com.siemens.SessionBean.FileManager.FileManagerBean.copyFile(FileManagerBean.java:43)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          Show
          Derya Altuntas added a comment - I am using open JPA 2.1.0 .I am receiving same error <openjpa-2.1.0-r422266:1071316 fatal user error> org.apache.openjpa.persistence.ArgumentException: You have supplied columns for "com.siemens.EntityBean.DBAccessManager.Role.authorizations", but this mapping cannot have columns in this context. at org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInfo.java:382) at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:120) 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:1801) 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.enhance.PCEnhancer.<init>(PCEnhancer.java:283) at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:254) at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:222) at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:134) at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:315) at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:239) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:213) 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 org.jboss.jpa.deployment.ManagedEntityManagerFactory.getNonTxEntityManager(ManagedEntityManagerFactory.java:72) at org.jboss.jpa.deployment.ManagedEntityManagerFactory.getTransactionScopedEntityManager(ManagedEntityManagerFactory.java:171) at org.jboss.jpa.deployment.PersistenceUnitDeployment.getTransactionScopedEntityManager(PersistenceUnitDeployment.java:178) at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:262) at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:191) at com.siemens.EntityBean.DBAccessManager.UserService.find(UserService.java:22) at com.siemens.SessionBean.FileManager.FileManagerBean.printUsers(FileManagerBean.java:86) at com.siemens.SessionBean.FileManager.FileManagerBean.copyFile(FileManagerBean.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          Hide
          Michael Dick added a comment -

          Sorry this is a late reply.

          I ran across this problem too. Check the version for the xsd in your persistence.xml file. If it's set to 1.0 I got an error similar to the one you posted. If you change the version to 2.0 you should get past the problem.

          Show
          Michael Dick added a comment - Sorry this is a late reply. I ran across this problem too. Check the version for the xsd in your persistence.xml file. If it's set to 1.0 I got an error similar to the one you posted. If you change the version to 2.0 you should get past the problem.
          Hide
          Koen Rousseau added a comment -

          Checked the version in persistence.xml, and in orm.xml, both are 2.0, yet specyfing a join-column tag in a OneToMany relationship still throws the above error in OpenJPA 2.1.1 (r422266).

          Show
          Koen Rousseau added a comment - Checked the version in persistence.xml, and in orm.xml, both are 2.0, yet specyfing a join-column tag in a OneToMany relationship still throws the above error in OpenJPA 2.1.1 (r422266).
          Hide
          Andras Szerdahelyi added a comment -

          for anyone who is google-ing this, i got the same exception despite being on the 2.0 spec, the problem was the entity referred in the relationship was not listed in persistence.xml..

          <class>package.RelatedEntity</class>

          Show
          Andras Szerdahelyi added a comment - for anyone who is google-ing this, i got the same exception despite being on the 2.0 spec, the problem was the entity referred in the relationship was not listed in persistence.xml.. <class>package.RelatedEntity</class>

            People

            • Assignee:
              Fay Wang
              Reporter:
              Rick Curtis
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development