You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by kostellodon <do...@citi.com> on 2011/03/01 06:45:36 UTC

Query using timestamp version field

I am using JPA 1.2.1  I have an entity with an update time field of type
Timestamp that is annotated as the version field.  I am trying to create a
query to find all entities of this type that were updated before a certain
time.  When getting the result list from the query, I get an exception.  The
code is as follows:
		String pql = "SELECT s FROM Scenario s WHERE s.updateDateTime < :endDate";
		Query queryObj = em.createQuery(pql);
		Timestamp t1 = new Timestamp((new Date()).getTime());
		queryObj.setParameter("endDate", t1);
		List<Scenario> scenarioList = queryObj.getResultList();

The exception is:
<openjpa-1.2.1-SNAPSHOT-r422266:686069 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Array index out of range:
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:253)
	at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:293)
	at com.citi.rel.domain.scenario.NoteTest.fetchDatedNote(NoteTest.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:599)
	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.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	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: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)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of
range: 0
	at org.apache.openjpa.jdbc.kernel.exps.PCPath.appendTo(PCPath.java:721)
	at
org.apache.openjpa.jdbc.kernel.exps.FilterValueImpl.appendTo(FilterValueImpl.java:63)
	at
org.apache.openjpa.jdbc.kernel.exps.FilterValueImpl.appendTo(FilterValueImpl.java:59)
	at
org.apache.openjpa.jdbc.sql.DBDictionary.comparison(DBDictionary.java:2732)
	at
org.apache.openjpa.jdbc.kernel.exps.CompareExpression.appendTo(CompareExpression.java:75)
	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)
	... 32 more


If I change the field to the insert time field, the query works, so it
appears that the problem is that the field is annotated as the Version
field.  Is there any way around this?

Don

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Query-using-timestamp-version-field-tp6076165p6076165.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Query using timestamp version field

Posted by Rick Curtis <cu...@gmail.com>.
I fixed the problem[1] in trunk. Let me know if you get a chance to try it
out.

Thanks,
Rick


[1]http://issues.apache.org/jira/browse/OPENJPA-1954

On Wed, Mar 2, 2011 at 9:20 AM, Rick Curtis <cu...@gmail.com> wrote:

> I'll take a look this morning to see what I can come up with.
>
> Thanks,
> Rick
>

Re: Query using timestamp version field

Posted by Rick Curtis <cu...@gmail.com>.
I'll take a look this morning to see what I can come up with.

Thanks,
Rick

Re: Query using timestamp version field

Posted by kostellodon <do...@citi.com>.
Hmm, further information comes out.  It seems to work with mine when I have
the field directly in my entity.  In my standard case, I have a basic entity
that my standard entities extend.  I have reduced by base entity to the
following:

@MappedSuperclass
public abstract class BasicEntity {
	@Column(name="update_user")
	private String updateUser;
	@Column(name="update_user_namespace")
	private String updateUserNamespace;
	@Version
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="update_datetime")
	private Timestamp updateDateTime;
	@Column(name="insert_user")
	private String insertUser;
	@Column(name="insert_user_namespace")
 	private String insertUserNamespace;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="insert_datetime")
	private Timestamp insertDateTime;
...
}

If I extend this basic entity, I get the issue.  If I don't use the base
class and have the updateDateTime directly in my class, the exception goes
away.


-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Query-using-timestamp-version-field-tp6076165p6078987.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Query using timestamp version field

Posted by Rick Curtis <cu...@gmail.com>.
Can I have you post your Entity? This seems to work with my unit test:

@Entity
public class TimestampedEntity {
    @Id
    @GeneratedValue
    private long id;

    @Version
    private Timestamp version;
...
}

        EntityManager em = emf.createEntityManager();
        String pql = "SELECT s FROM TimestampedEntity s WHERE s.version <
:endDate";
        Query queryObj = em.createQuery(pql);
        Timestamp t1 = new Timestamp((new Date()).getTime());
        queryObj.setParameter("endDate", t1);
        List<TimestampedEntity> scenarioList = queryObj.getResultList();

Thanks,
Rick

On Tue, Mar 1, 2011 at 3:58 PM, kostellodon <do...@citi.com>wrote:

> I'm doing this query within a unit test, and am using runtime enhancement
> via
> the javaagent.
>
> I've tried this with both 1.2.2 and 2.1.0 and see the same index out of
> bounds exception in both cases.
>
> Either querying another timestamp field or removing the version annotation
> from the update field causes the exception to go away.  Marking a field
> that
> is a Long as the version field also makes it go away, so it appears to be
> directly related to querying against a Timestamp version field.
>
>

Re: Query using timestamp version field

Posted by kostellodon <do...@citi.com>.
I'm doing this query within a unit test, and am using runtime enhancement via
the javaagent.

I've tried this with both 1.2.2 and 2.1.0 and see the same index out of
bounds exception in both cases.

Either querying another timestamp field or removing the version annotation
from the update field causes the exception to go away.  Marking a field that
is a Long as the version field also makes it go away, so it appears to be
directly related to querying against a Timestamp version field.


-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Query-using-timestamp-version-field-tp6076165p6078869.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Query using timestamp version field

Posted by Michael Dick <mi...@gmail.com>.
I'll add Rick's usual question: how are you enhancing your entities?

There's a post from last year about index out of bounds problems in
PCPath<http://openjpa.208410.n2.nabble.com/ArgumentException-when-using-generics-td5073975.html>,
but it's not quite the same scenario.

Also, could you give your scenario a try with OpenJPA 1.2.2?

-mike

On Mon, Feb 28, 2011 at 11:45 PM, kostellodon <do...@citi.com>wrote:

> I am using JPA 1.2.1  I have an entity with an update time field of type
> Timestamp that is annotated as the version field.  I am trying to create a
> query to find all entities of this type that were updated before a certain
> time.  When getting the result list from the query, I get an exception.
>  The
> code is as follows:
>                String pql = "SELECT s FROM Scenario s WHERE
> s.updateDateTime < :endDate";
>                Query queryObj = em.createQuery(pql);
>                Timestamp t1 = new Timestamp((new Date()).getTime());
>                queryObj.setParameter("endDate", t1);
>                List<Scenario> scenarioList = queryObj.getResultList();
>
> The exception is:
> <openjpa-1.2.1-SNAPSHOT-r422266:686069 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: Array index out of range:
> 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:253)
>        at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:293)
>        at
> com.citi.rel.domain.scenario.NoteTest.fetchDatedNote(NoteTest.java:70)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
>        at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
>        at java.lang.reflect.Method.invoke(Method.java:599)
>        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.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>        at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>        at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>        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: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)
> Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of
> range: 0
>        at
> org.apache.openjpa.jdbc.kernel.exps.PCPath.appendTo(PCPath.java:721)
>        at
>
> org.apache.openjpa.jdbc.kernel.exps.FilterValueImpl.appendTo(FilterValueImpl.java:63)
>        at
>
> org.apache.openjpa.jdbc.kernel.exps.FilterValueImpl.appendTo(FilterValueImpl.java:59)
>        at
> org.apache.openjpa.jdbc.sql.DBDictionary.comparison(DBDictionary.java:2732)
>        at
>
> org.apache.openjpa.jdbc.kernel.exps.CompareExpression.appendTo(CompareExpression.java:75)
>        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)
>        ... 32 more
>
>
> If I change the field to the insert time field, the query works, so it
> appears that the problem is that the field is annotated as the Version
> field.  Is there any way around this?
>
> Don
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Query-using-timestamp-version-field-tp6076165p6076165.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>