You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by stlecho <st...@gmail.com> on 2010/05/19 10:33:45 UTC
ArgumentException when using generics
I'm facing an issue when using a Named Query with a class that uses generics.
Without using generics, a call to the Named Query works perfect. When using
generics, a call to the Named Query results in a ArgumentException.
I'm using version 1.2.2 of OpenJPA. I would be very pleased if someone could
help me to solve this issue.
A description of both scenarios:
Without generics
The 'VATRResponse' class has a ManyToOne relationship with the 'VATRMessage'
class. The 'VATRResponse' class has a named query
'VATRResponse.findResponsesByMsgId'. When calling this query - by using the
'findResponsesForMessageId' method - without using generics, I'm getting a
correct result. So far so good :o)
[code]
@Entity
@NamedQueries( {
@NamedQuery(
name = "VATRResponse.findResponsesByMsgId",
query = "select r from VATRResponse r where r.message.id=:msgId")}
)
public class VATRResponse {
@ManyToOne
public VATRMessage message;
}
[/code]
[code]
@Entity
public class VATRMessage extends ViesMessage {}
[/code]
[code]
@Override
@SuppressWarnings("unchecked")
public List<VATRResponse> findResponsesForMessageId(Long msgId) {
Query query =
entityManager.createNamedQuery("VATRResponse.findResponsesByMsgId");
query.setParameter("msgId",msgId);
List rply = query.getResultList();
return rply;
}
[/code]
With generics
Based on the above code, I've created a generic 'ViesResponse' class. This
class has the ManyToOne relationship to a generic MSG. The
'VATRResponse.findResponsesByMsgId' named query remains on the
'VATRResponse' class.
When calling the same 'findResponsesForMessageId' method, I'm getting an
ArgumentException (see below for the complete stack trace).
[code]
@MappedSuperclass
public abstract class ViesResponse<MSG extends ViesMessage> extends
IdentityObject {
@ManyToOne
public MSG message;
}
[/code]
[code]
@Entity
@NamedQueries( {
@NamedQuery(
name = "VATRResponse.findResponsesByMsgId",
query = "select r from VATRResponse r where r.message.id=:msgId")}
)
[/code]
[code]
public class VATRResponse extends ViesResponse<VATRMessage> {
}
[/code]
[stacktrace]
ATTENTION: A system exception occurred during an invocation on EJB
VATRManagerImpl method public java.util.List
be.minfin.fgov.jpa.proto3.business.VATRManagerImpl.findResponsesForMessageId(java.lang.Long)
javax.ejb.EJBException
at
com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5030)
at
com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:4928)
at
com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4716)
at
com.sun.ejb.containers.StatefulSessionContainer.postInvokeTx(StatefulSessionContainer.java:1626)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1941)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1892)
at
com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
at
com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy80.findResponsesForMessageId(Unknown Source)
at
be.minfin.fgov.jpa.proto3.VATRManagerTest.receiveMessage(VATRManagerTest.java:15)
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.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.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
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:236)
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)
Caused by: <openjpa-1.2.2-r422266:898935 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: 0
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:857)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:779)
at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:254)
at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:294)
at
be.minfin.fgov.jpa.proto3.business.VATRManagerImpl.findResponsesForMessageId(VATRManagerImpl.java:24)
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.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at
org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at
com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4010)
at
com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5183)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5163)
at
com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
... 27 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.openjpa.jdbc.kernel.exps.PCPath.appendTo(PCPath.java:721)
at
org.apache.openjpa.jdbc.kernel.exps.EqualExpression.appendTo(EqualExpression.java:71)
at
org.apache.openjpa.jdbc.kernel.exps.CompareEqualExpression.appendTo(CompareEqualExpression.java:98)
at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.buildWhere(SelectConstructor.java:240)
at
org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.evaluate(SelectConstructor.java:81)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.createWhereSelects(JDBCStoreQuery.java:339)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeQuery(JDBCStoreQuery.java:179)
at
org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeQuery(ExpressionStoreQuery.java:681)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:988)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:848)
[/stacktrace]
--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5073975.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
RE: ArgumentException when using generics
Posted by C N Davies <cn...@cndavies.com>.
Why not just use String.format(); to work around the issue and log a jira or
fix the code and submit it.
-----Original Message-----
From: stlecho [mailto:stlecho@gmail.com]
Sent: Friday, 28 May 2010 6:40 PM
To: users@openjpa.apache.org
Subject: Re: ArgumentException when using generics
Using
select r from VATRResponse r where r.message.id=?1
instead of
select r from VATRResponse r where r.message.id=:msgId
results in the same
java.lang.ArrayIndexOutOfBoundsException: 0
The http://openjpa.208410.n2.nabble.com/file/n5112192/jpa-proto3.zip
jpa-proto3.zip file contains the Eclipse project I'm using.
--
View this message in context:
http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp
5073975p5112192.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ArgumentException when using generics
Posted by stlecho <st...@gmail.com>.
Using
select r from VATRResponse r where r.message.id=?1
instead of
select r from VATRResponse r where r.message.id=:msgId
results in the same
java.lang.ArrayIndexOutOfBoundsException: 0
The http://openjpa.208410.n2.nabble.com/file/n5112192/jpa-proto3.zip
jpa-proto3.zip file contains the Eclipse project I'm using.
--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5112192.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ArgumentException when using generics
Posted by stlecho <st...@gmail.com>.
I've debugged more in detail and I found the following:
In JDBCStoreQuery.executeQuery
-base and metas both contain
be.minfin.fgov.jpa.proto3.entity.VATRResponse
-params contains [1].
In SelectConstructor.evaluate
-parameterTypes.data contains [null, null, null, null, null, null,
msgId=class java.lang.Long, null]
-sel contains SELECT FROM VATRResponse t0 INNER JOIN VATRMessage t1 ON
t0.message = t1.id
In EqualExpression(CompareEqualExpression).appendTo
-ctx.params contains [1]
In Param.calculateValue
-other._actions contains contains
[0|be.minfin.fgov.jpa.proto3.entity.ViesResponse.message,
0|be.minfin.fgov.jpa.proto3.entity.IdentityObject.id]
-other._candidate contains be.minfin.fgov.jpa.proto3.entity.VATRResponse
-sel contains SELECT FROM VATRResponse t0 INNER JOIN VATRMessage t1 ON
t0.message = t1.id
-otherState.cols contains[]
In PCPath.getColumns
-pstate.field contains be.minfin.fgov.jpa.proto3.entity.IdentityObject.id
-pstate.cols contains []
The fact that pstate.cols contains [] causes the
ArrayIndexOutOfBoundsException, because in PCPath.appendTo, the following
code is executed: "Column col = getColumns(state)[index];" with index == 0.
[stacktrace]
PCPath.appendTo(Select, ExpContext, ExpState, SQLBuffer, int) line: 721
EqualExpression.appendTo(Select, ExpContext, BinaryOpExpState, SQLBuffer,
boolean, boolean) line: 71
EqualExpression(CompareEqualExpression).appendTo(Select, ExpContext,
ExpState, SQLBuffer) line: 98
SelectConstructor.buildWhere(Select, ExpContext, ExpState, Expression) line:
240
SelectConstructor.evaluate(ExpContext, Select, String, QueryExpressions,
QueryExpressionsState) line: 81
JDBCStoreQuery.createWhereSelects(List, ClassMapping[], List, boolean,
BitSet, BitSet, ExpressionFactory[], QueryExpressions[],
QueryExpressionsState[], ExpContext, int) line: 339
JDBCStoreQuery.executeQuery(StoreQuery$Executor, ClassMetaData,
ClassMetaData[], boolean, ExpressionFactory[], QueryExpressions[], Object[],
StoreQuery$Range) line: 179
[/stacktrace]
--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5112157.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ArgumentException when using generics
Posted by stlecho <st...@gmail.com>.
I've tried to enable and disable the Runtime Enhancer, but I'm getting the
"ArgumentException" error again. See
http://openjpa.208410.n2.nabble.com/file/n5102776/openjpa_stacktrace.txt
openjpa_stacktrace.txt for the complete stacktrace.
As I'm blocked by this issue, I would be please if someone could help me
solving it ;o)
--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5102776.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ArgumentException when using generics
Posted by stlecho <st...@gmail.com>.
When the Runtime Enhancement Agent is not used, a "This configuration
disallows runtime optimization, but the following listed types were not
enhanced at build time or at class load time with a javaagent:" error (see
below for a snapshot of the generated snapshot) is generated.
[stacktrace]
"Caused by: <openjpa-2.0.0-r422266:935683 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: This configuration
disallows runtime optimization, but the following listed types were not
enhanced at build time or at class load time with a javaagent: "
be.minfin.fgov.jpa.proto3.entity.VATRMessage
be.minfin.fgov.jpa.proto3.entity.IdentityObject
be.minfin.fgov.jpa.proto3.entity.ViesMessage
be.minfin.fgov.jpa.proto3.entity.ViesResponse
be.minfin.fgov.jpa.proto3.entity.VATRResponse".
at
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:116)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:304)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:228)
at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202)
at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:213)
at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:57)
at
com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:197)
at
com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:521)
at
be.minfin.fgov.jpa.proto3.business.VATRManagerImpl.findResponsesForMessageId(VATRManagerImpl.java:22)
"
[/stacktrace]
Using underneath code, results in "Field
"be.minfin.fgov.jpa.proto3.entity.ViesMessage.responses" cannot declare that
it is mapped by another field. Its mapping strategy
(org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy) does not support
mapping by another field.".
[code]
@OneToMany(cascade=CascadeType.ALL,mappedBy="message")
protected List<RESP> responses;
[/code]
Using underneath code, results in a "correct" result. The
ViesMessage.responses property is however persisted as a BLOB in the
VIESMESSAGE table and not in the VIESRESPONSE table.
[code]
@OneToMany(cascade=CascadeType.ALL)
protected List<RESP> responses;
[/code]
Kevin Sutter wrote:
>
> Was it the Runtime Enhancement agent that got you
> working? Or, was it the changes to your code? Or, were both required?
>
--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5078448.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ArgumentException when using generics
Posted by Kevin Sutter <kw...@gmail.com>.
Hi,
Reading through your postings, I'm trying to figure out what actually helped
you get this running. Was it the Runtime Enhancement agent that got you
working? Or, was it the changes to your code? Or, were both required?
The Runtime Enhancement agent is already part of the 1.2.x base, so there's
nothing to merge back to the 1.2.x base from that perspective.
Thanks,
Kevin
On Wed, May 19, 2010 at 5:39 AM, stlecho <st...@gmail.com> wrote:
>
> When using OpenJPA v2.0.0 and the OpenJPA Agent for Runtime Enhancement,
> I've
> been able to make it work :o). The modifications I had to do are listed
> below.
>
> When switching back to OpenJPA v1.2.2 and leaving out the OpenJPA Agent for
> Runtime Enhancement the modified code does not work :o(.
>
> Unfortunately, the v2.0.0 is not (yet) a standard within the company I'm
> working so I can not use it.
> Would it be possible to fix this issue in the v1.2.x version of OpenJPA ?
>
> Non-working version
> [code]
> public class ViesMessage<RESP extends ViesResponse> extends IdentityObject
> {
> @OneToMany(cascade=CascadeType.ALL,
> mappedBy="message",targetEntity=VATRResponse.class)
> protected List<RESP> responses;
> [/code]
>
> Working version
> [code]
> public abstract class ViesMessage<RESP extends ViesResponse> extends
> IdentityObject {
> @OneToMany(cascade=CascadeType.ALL)
> protected List<RESP> responses;
> [/code]
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5074351.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
Re: ArgumentException when using generics
Posted by stlecho <st...@gmail.com>.
When using OpenJPA v2.0.0 and the OpenJPA Agent for Runtime Enhancement, I've
been able to make it work :o). The modifications I had to do are listed
below.
When switching back to OpenJPA v1.2.2 and leaving out the OpenJPA Agent for
Runtime Enhancement the modified code does not work :o(.
Unfortunately, the v2.0.0 is not (yet) a standard within the company I'm
working so I can not use it.
Would it be possible to fix this issue in the v1.2.x version of OpenJPA ?
Non-working version
[code]
public class ViesMessage<RESP extends ViesResponse> extends IdentityObject {
@OneToMany(cascade=CascadeType.ALL,
mappedBy="message",targetEntity=VATRResponse.class)
protected List<RESP> responses;
[/code]
Working version
[code]
public abstract class ViesMessage<RESP extends ViesResponse> extends
IdentityObject {
@OneToMany(cascade=CascadeType.ALL)
protected List<RESP> responses;
[/code]
--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-tp5073975p5074351.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.