Hello,
While trying to use enumeration as a key in a persistent map I fail at various stages - either at enhance-time or runtime. Is enumeration a valid key type?
i.e.:
<enum>
public enum TSType implements java.io.Serializable {
        
        
        G, BP, RP, SM, RVS, RADIAL_VELOCITY, BPmRP,  G_CCD
        
}

then some source class is identified by sourceId.class and looks like:
<Source>
        @Id
        @Column(name="surveyId")
        private long aSurveyId;
        

        @Id
        @Column(name = "srcId")
        private long sourceId;

        @OneToMany(mappedBy="source",cascade=CascadeType.ALL)
        @MapKey(name="tsType")

        private Map<TSType, TSImpl> tsMap;

where
TSImpl is identified by TSImplId and looks like:
<TSImpl>

        @Id
@ManyToOne(optional=false,fetch = FetchType.LAZY,cascade=CascadeType.ALL)
        @PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name = "survey_pk", referencedColumnName="surveyId"), @PrimaryKeyJoinColumn(name = "source_pk", referencedColumnName = "srcId")
        })
        protected Source source;

        @Id
        @Basic(optional=false)
        @Enumerated(EnumType.ORDINAL)
        @Column(name="tsType",updatable=false)
        private TimeSeriesType tsType;




I would like to avoid having a join table (@PersistenMap creates join table to my knowledge and gives same error) and thus I used MapKey.

Enhancer works without warnings and insertion as well. Retrieval gives an exception shown below. Same behaviour for 1.2 and trunk versions.


Another question - I didn't manage to persist map form root object - is it mandatory to call persist on a map itself if its embedded in Source?

I would appreciate any hints...

java.lang.ClassCastException: xxx.TSType cannot be cast to org.apache.openjpa.util.ObjectId
        at TSImpl.pcCopyKeyFieldsToObjectId(TSImpl.java)
at org .apache .openjpa.enhance.PCRegistry.copyKeyFieldsToObjectId(PCRegistry.java:172) at org .apache.openjpa.util.ApplicationIds.fromPKValues(ApplicationIds.java: 218) at org .apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java: 218) at org .apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java: 149) at org .apache .openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:966) at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:278) at org.apache.openjpa.jdbc.sql.SelectImpl $SelectResult.load(SelectImpl.java:2397) at org .apache .openjpa .jdbc .meta .strats .RelationToManyInverseKeyFieldStrategy .loadElement(RelationToManyInverseKeyFieldStrategy.java:87) at org .apache .openjpa .jdbc .meta .strats .StoreCollectionFieldStrategy.load(StoreCollectionFieldStrategy.java: 636) at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java: 822) at org .apache .openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:682) at org .apache .openjpa .kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:116) at org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:78) at org .apache .openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:2925) at org .apache .openjpa.kernel.StateManagerImpl.loadField(StateManagerImpl.java:3003) at org .apache .openjpa .kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:1496) at org .apache .openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java: 1481)
        at Sourcel.pcGetTSMap(SourceImpl.java)
        at Sourcel.getTS(SourceImpl.java:292)
        at SourceImplTest.PersistsSource(SourceImplTest.java:712)
        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:597)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org .junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org .junit .internal .runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87) at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java: 77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org .junit .internal .runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88) at org .junit .internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java: 51) at org.junit.internal.runners.JUnit4ClassRunner $1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java: 27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org .junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org .eclipse .jdt .internal .junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org .eclipse .jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org .eclipse .jdt .internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 460) at org .eclipse .jdt .internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 673) at org .eclipse .jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 386) at org .eclipse .jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 196)


Reply via email to