thanks marc,

this seems like a very common use case. for example, Book and Page entities. A Book has many Pages. obviously a Page object needs to somehow factor it's Book into it's ID, otherwise page 1 in Book A and page 1 in Book B can't both exist.

i think i worked around, considering the example above, by adding an additional String bookName field in Page and making that the ID. that field doesn't have a setter of it's own and gets set when the book field is set. this results in a less than normalized table, but oh well.

thanks for your help.

Marc Prud'hommeaux wrote:
Jeffrey-

The problem is that a @ManyToOne cannot be an @Id (as per section 2.1.4 of the JPA spec). You could do it with an @EmbeddedId, but only if you actually embed all of the fields of the embedded class as primary keys of the (which doesn't appear to be what you want).

I'm a little surprised that OpenJPA didn't give your an earlier warning or error about this.



On Aug 1, 2007, at 9:52 PM, Jeffrey Blattman wrote:

thanks.

package com.sun.portal.pom;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlElement;

@IdClass (com.sun.portal.pom.PreferenceId.class)
@javax.persistence.Entity
public class Preference implements Serializable {
   @Id
   @Column(
       name = "PREFERENCE_NAME",
       nullable = false
   )
   @XmlElement (
       name = "name"
   )       private String name;       @Column(
       name="PREFERENCE_VALUES",
       nullable = false
   )
   @XmlElement (
       name = "value"
   )       private List<String> values = new ArrayList<String>();
    @Id
   @ManyToOne (
     cascade = CascadeType.ALL,
     optional = false
   )
   private Preferences preferences;

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public List<String> getValues() {
       return values;
   }

   public void setValues(List<String> values) {
       this.values = values;
   }
         public boolean equals(Object o) {
       if (!(o instanceof Preference)) {
           return false;
       }
             Preference other = (Preference)o;
             PreferenceId id = new PreferenceId(this);
       PreferenceId otherId = new PreferenceId(other);
             return id.equals(otherId);
   }
   public int hashCode() {
       PreferenceId id = new PreferenceId(this);
       return id.hashCode();
   }

   public Preferences getPreferences() {
       return preferences;
   }

   public void setPreferences(Preferences preferences) {
       this.preferences = preferences;
   }
}


Marc Prud'hommeaux wrote:
Jeffrey-

Your attachment got stripped out by the mailing list gateway.

Can you paste in the code for Preference.java?


On Aug 1, 2007, at 9:19 PM, Jeffrey Blattman wrote:

hi marc,

because there's no pointer to any particular class in the array index out of bound trace, i attached the project consisting of 12 classes. you if you start derby on localhost, you can do a mvn test and see the problem.

also, i tried this w/ 0.9.6-incubating, and i get a different problem ... the other two problems go away.

testPersist(com.sun.portal.pom.PersistTest) Time elapsed: 2.496 sec <<< ERROR! java.lang.VerifyError: (class: com/sun/portal/pom/Preference, method: pcCopyKeyFieldsToObjectId signature: (Ljava/lang/Object;)V) Bad type in putfield/putstatic
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:242)
at org.apache.openjpa.meta.MetaDataRepository.classForName(MetaDataRepository.java:1224) at org.apache.openjpa.meta.MetaDataRepository.loadPersistentTypes(MetaDataRepository.java:1212) at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:145) at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:127) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:164) at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:139) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:187) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:140) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:52) at com.sun.portal.pom.PersistTest.removeEntity(PersistTest.java:151)

Marc Prud'hommeaux wrote:
Jeffrey-

Hmm ... that's an odd one. Do you have more than one field marked as the primary key (@Id)? If so, do you have an identity class defined for the entity?

Maybe if you can just paste the code for the entity into an e-mail, something might jump out at us.



On Aug 1, 2007, at 7:56 PM, Jeffrey Blattman wrote:

hi marc,

yes setting the query compilation flag to false made that error go away. however, now i get the trace below, which looks even scarier.

any ideas? i can make my project available if anyone wants to try it locally.

0.9.7-incubating nonfatal general error> org.apache.openjpa.persistence.PersistenceException: 1 at org.apache.openjpa.kernel.BrokerImpl.newObjectId(BrokerImpl.java:1115) at org.apache.openjpa.kernel.DelegatingBroker.newObjectId(DelegatingBroker.java:257) at org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:348) at com.sun.portal.pom.PersistTest.removeEntity(PersistTest.java:156) at com.sun.portal.pom.PersistTest.cleanup(PersistTest.java:211) at com.sun.portal.pom.PersistTest.testPersist(PersistTest.java:220) 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 junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
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.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
       at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.retrieve(ApplicationIds.java:544) at org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.fetchStringField(ApplicationIds.java:532) at com.sun.portal.pom.Entity.pcCopyKeyFieldsToObjectId(Entity.java) at org.apache.openjpa.enhance.PCRegistry.copyKeyFieldsToObjectId(PCRegistry.java:160) at org.apache.openjpa.util.ApplicationIds.fromPKValues(ApplicationIds.java:180) at org.apache.openjpa.kernel.BrokerImpl.newObjectId(BrokerImpl.java:1105)

Marc Prud'hommeaux wrote:
Jeffrey-

That does look like a bug (although not one I've ever seen when having a dependency on openjpa).

If you set the property "openjpa.QueryCompilationCache" to "false", do you still see the error?



On Aug 1, 2007, at 6:52 PM, Jeffrey Blattman wrote:

hi,

this is on 0.9.7-incubating. i am trying to use openjpa in a unit test from a maven2 project. i am depending on "openjpa-all" as a "compile" type dependency. when my unit test runs, i see the stack trace below.

CacheMap is in the openjpa-all-0.9.7-incubating.jar file in .m2/repository ...

i see issue 256:
https://issues.apache.org/jira/browse/OPENJPA-256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12503158

which looks similar. is there any workaround for this?

125 pomtest INFO [main] openjpa.Runtime - Starting OpenJPA 0.9.7-incubating 615 pomtest INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.DerbyDictionary". <0.9.7-incubating nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: org.apache.openjpa.lib.util.ParseException: Instantiation of plugin "QueryCompilationCache" with value "true" caused an error "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The alias or class name may have been misspelled (as it closely matches the valid plugin alias "true"), or the class may not be available in the class path. Valid aliases for this plugin are: [all, false, true] at org.apache.openjpa.lib.conf.Configurations.getCreateException(Configurations.java:341) at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:198) at org.apache.openjpa.lib.conf.ObjectValue.newInstance(ObjectValue.java:103) at org.apache.openjpa.conf.QueryCompilationCacheValue.newInstance(QueryCompilationCacheValue.java:57) at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:101) at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:79) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getQueryCompilationCacheInstance(OpenJPAConfigurationImpl.java:1402) 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.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:282) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1411) at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:547) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:157) at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:190) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:143) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:55) at com.sun.portal.pom.PersistTest.removeEntity(PersistTest.java:151) at com.sun.portal.pom.PersistTest.cleanup(PersistTest.java:211) at com.sun.portal.pom.PersistTest.testPersist(PersistTest.java:220) 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 junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
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.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125) at org.apache.maven.surefire.Surefire.run(Surefire.java:132) 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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818) Caused by: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
       at serp.util.Strings.toClass(Strings.java:211)
       at serp.util.Strings.toClass(Strings.java:140)
at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:194)
       ... 46 more
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:193) at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:190) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:143) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:55) at com.sun.portal.pom.PersistTest.removeEntity(PersistTest.java:151) at com.sun.portal.pom.PersistTest.cleanup(PersistTest.java:211) at com.sun.portal.pom.PersistTest.testPersist(PersistTest.java:220) 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 junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
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.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125) at org.apache.maven.surefire.Surefire.run(Surefire.java:132) 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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818) Caused by: java.lang.RuntimeException: There were errors initializing your configuration: org.apache.openjpa.lib.util.ParseException: Instantiation of plugin "QueryCompilationCache" with value "true" caused an error "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap". The alias or class name may have been misspelled (as it closely matches the valid plugin alias "true"), or the class may not be available in the class path. Valid aliases for this plugin are: [all, false, true] at org.apache.openjpa.lib.conf.Configurations.getCreateException(Configurations.java:341) at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:198) at org.apache.openjpa.lib.conf.ObjectValue.newInstance(ObjectValue.java:103) at org.apache.openjpa.conf.QueryCompilationCacheValue.newInstance(QueryCompilationCacheValue.java:57) at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:101) at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:79) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getQueryCompilationCacheInstance(OpenJPAConfigurationImpl.java:1402) 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.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:282) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1411) at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:547) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:157) at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:190) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:143) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:55) at com.sun.portal.pom.PersistTest.removeEntity(PersistTest.java:151) at com.sun.portal.pom.PersistTest.cleanup(PersistTest.java:211) at com.sun.portal.pom.PersistTest.testPersist(PersistTest.java:220) 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 junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
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.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125) at org.apache.maven.surefire.Surefire.run(Surefire.java:132) 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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818) Caused by: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.openjpa.util.CacheMap
       at serp.util.Strings.toClass(Strings.java:211)
       at serp.util.Strings.toClass(Strings.java:140)
at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:194)
       ... 46 more
at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:296) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1411) at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:547) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:157)
       ... 33 more








Reply via email to