openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Vorburger" <mvorbur...@odyssey-group.com>
Subject ArrayIndexOutOfBoundsException in org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.retrieve
Date Tue, 03 Mar 2009 19:57:35 GMT
Hello,
 
I'm getting a ArrayIndexOutOfBoundsException in
org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.retrieve(A
pplicationIds.java:602), full stack trace below.
 
This occurs when I try to use application ID Identity Hierarchies as per
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/
jpa_overview_pc_identity.html#jpa_overview_pc_identity_hierarchy, may be
because I was trying to use them together with Entities as Identity
Fields as per
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/
ref_guide_pc_oid.html#ref_guide_pc_oid_entitypk ... 

Both of this is not JPA 1.0 spec, is it? Will this later be possible via
standard in JPA 2.0? Is there a "better" (in the sense of spec
compliant) way to do this, or a workaround or even better bug fix for
OpenJPA? Here is an attempt to sketch out the model that this occurs
with:
 
@javax.persistence.Entity(name = "DictLabel")
@IdClass(DictLabelId.class)
@javax.persistence.Table(name = "dict_label_vw")
@javax.persistence.Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="entity_dict_id",
discriminatorType=DiscriminatorType.INTEGER)
public abstract class DictLabelEntity {
 
 @Basic(optional = false)
 @javax.persistence.Column(name = "name", nullable = false)
 private String name;
 
 @Id
 @javax.persistence.ManyToOne(cascade = {CascadeType.PERSIST,
   CascadeType.MERGE, CascadeType.REFRESH}, fetch = FetchType.LAZY,
optional = false)
 @javax.persistence.JoinColumn(name = "language_dict_id", nullable =
false)
 private DictLanguageEntity language;
 
 @Id
 @Basic(optional = false)
 @javax.persistence.Column(name = "entity_dict_id", nullable = false)
 private long entityRef;
}

@Entity(name = "DictLanguageLabel")
@IdClass(DictLanguageLabelId.class)
@DiscriminatorValue(value="1106")
public class DictLanguageLabelEntity extends DictLabelEntity {
 
    @Id
    @javax.persistence.ManyToOne(cascade = {CascadeType.PERSIST,
            CascadeType.MERGE, CascadeType.REFRESH}, fetch =
FetchType.LAZY, optional = false)
    @javax.persistence.JoinColumn(name = "object_dict_id", nullable =
false)
    private DictLanguageEntity forLanguage;
}

public abstract class DictLabelId implements Serializable {
    public long language;
    public long entityRef;
    // ... equals() ... hashCode() ...
}

public class DictLanguageLabelId extends DictLabelId {
    public long forLanguage;
    // ... equals() ... hashCode() ...
}
 
With this, a simple query for "SELECT l FROM DictLanguageLabel l" leads
to the exception below.

The DictLanguageEntity is another entity deliberately omitted, it's a
"standard" one with a simple @Id private long id.  If this model seems
to make little sense, I have to admit that it is simplified, as in real
life there are other subclasses of DictLabelEntity, where that
object_dict_id is a ManyToOne to other entities than DictLanguageEntity.

I actually found a work-around, as follows: No DictLanguageLabelId
extends DictLabelId (and no @IdClass on DictLanguageLabelEntity), and
make DictLabelId not abstract.  Then add the following to the
DictLabelEntity to "double map" that "object_dict_id" column (which is
also mapped in the DictLanguageLabelEntity subclass), and remove the @Id
from the forLanguage in DictLanguageLabelEntity:

    @Id
    @Basic(optional = false)
    @javax.persistence.Column(name = "object_dict_id", nullable = false)
    private long objectRef;

and add a public long objectRef; to the DictLabelId (with updated
equals() and hashCode()).  seems to work, but is clearly a work-around
for what appears to be a bug...

Regards,
Michael
 
___
<openjpa-1.2.0-r422266:683325 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: 2
 at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:814)
 at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775)
 at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:771)
 at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:5
17)
 at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:254)
 at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:29
3)
 at com.odcgroup.tangij.nls.LabelsDAO.getAllLabels(LabelsDAO.java:38)
 at
com.odcgroup.tangij.nls.LabelsDAOTest.testLabels(LabelsDAOTest.java:34)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
 at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.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(Met
hodRoadie.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(JUnit4Clas
sRunner.java:88)
 at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunne
r.java:51)
 at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.jav
a:44)
 at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:2
7)
 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(JUnit4Tes
tReference.java:38)
 at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja
va:38)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:460)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:673)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:386)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
 at
org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.retrieve(A
pplicationIds.java:602)
 at
org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.fetchLongF
ield(ApplicationIds.java:578)
 at
com.odcgroup.tangij.domainmodel.DictLanguageLabelEntity.pcCopyKeyFieldsT
oObjectId(DictLanguageLabelEntity.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:
213)
 at
org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java:
150)
 at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.ja
va:910)
 at
org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:278)
 at
org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.load(SelectImpl.java
:2391)
 at
org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:272)
 at
org.apache.openjpa.jdbc.kernel.InstanceResultObjectProvider.getResultObj
ect(InstanceResultObjectProvider.java:59)
 at
org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:3
6)
 at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1228)
 at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
 at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:805)
 ... 29 more


____________________________________________________________

 This email and any files transmitted with it are CONFIDENTIAL and intended
  solely for the use of the individual or entity to which they are addressed.
 Any unauthorized copying, disclosure, or distribution of the material within
  this email is strictly forbidden.
 Any views or opinions presented within this e-mail are solely those of the
  author and do not necessarily represent those of Odyssey Financial
Technologies SA unless otherwise specifically stated.
 An electronic message is not binding on its sender. Any message referring to
  a binding engagement must be confirmed in writing and duly signed.
 If you have received this email in error, please notify the sender immediately
  and delete the original.

Mime
View raw message