You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by dbrenck <Di...@gmx.de> on 2008/11/23 02:35:14 UTC

@Version and Query using version column cause trouble?

geronimo version 2.1.2

Any idea why the following query fails?

Serverside:

 pu for xxxx classes  TRACE  [ejbd 10] openjpa.Query - Executing query:
[SELECT entity FROM TypeEntity entity WHERE ( entity.id = :id ) AND (
entity.version = ( SELECT MAX( sameentity.version ) FROM TypeEntity
sameentity WHERE sameentity.id = :id ))] with parameters: {id=1011}

Clientside:

javax.ejb.EJBException: The bean encountered a non-application exception.;
nested exception is:
        <openjpa-1.0.2-r420667:627158 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: 0
        at
org.apache.openejb.client.EJBInvocationHandler.convertException(EJBInvocationHandler.java:219)
        at
org.apache.openejb.client.EJBObjectHandler._invoke(EJBObjectHandler.java:157)
        at
org.apache.openejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:117)
        at
org.apache.openejb.client.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:52)
        at $Proxy0.findEntityById(Unknown Source)
        at
org.brenckmann.java.prj.ejbclient.Client.listTypes(Client.java:123)
        at org.brenckmann.java.prj.ejbclient.Client.main(Client.java:50)
Caused by: <openjpa-1.0.2-r420667:627158 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: 0
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:851)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:773)
        at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525)
        at
org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:237)
        at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:277)
        at
org.brenckmann.java.ejb.core.AbstractEntitiesBean.findEntityById(AbstractEntitiesBean.java:115)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Column 'id' and 'version' are primary-key columns (and getter methods are
tagged @Id)
If I remove @Version from getVersion() everything is fine. Is it forbidden
to use a column tagged @Version in a Query?

Btw.: This thing fails when calling query.getSingleResult() it fails too
using query.getResultList() which is AbstractEntitiesBean.java:115


-- 
View this message in context: http://www.nabble.com/%40Version-and-Query-using-version-column-cause-trouble--tp20642421s134p20642421.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: @Version and Query using version column cause trouble?

Posted by dbrenck <Di...@gmx.de>.
Hi and ty Markus

The @Version tag is part of the EJB 3.0 spec (it's not JPA specific), which
also allows the use of @Id and @Version on the same field. As geronimo and
JPA are EJB 3.0 compliant, I'd expect this to work.

Of cause @Version is support for multi-user-environment, and of cause my
column named 'version' exactly handled this in a none-ejb-none-jpa
environment.

In the end, the specs leave the option to developer, wether to use @Version
or not.

1) In case I use @Version, I must not do changes to the 'version'
column/field on my own.
2) In case I don't use it, I have to manage version increments and checks on
my own.

When doing 1) I have to expect PersistenceExceptions due to failed
optimistic locking. (Two users did updates on the same Entity version.)

When doing 2) I have to expect my own management exceptions and/or SQL
Exceptions in case my management failed (mainly exceptions about key
violations...).

In either case I'd expect a failure of a query or a success but I'd not at
all expect it to fail in 1) and to succeed in 2) or the other way round.

>  pu for xxxx classes  TRACE  [ejbd 10] openjpa.Query - Executing query:
> [SELECT entity FROM TypeEntity entity WHERE ( entity.id = :id ) AND (
> entity.version = ( SELECT MAX( sameentity.version ) FROM TypeEntity
> sameentity WHERE sameentity.id = :id ))] with parameters: {id=1011}

If the underlying sql works (and it does) there is no reason for me, why the
ejb Query should fail.

Notice: It fails with an ArrayOutOfBoundsException(!) (or something like
that)

Maybe I might have to accept a reasonable PersistenceException in turn!

Please correct me if my thoughts went wrong somewhere.

Ty
-- 
View this message in context: http://www.nabble.com/%40Version-and-Query-using-version-column-cause-trouble--tp20642421s134p20649285.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: @Version and Query using version column cause trouble?

Posted by Markus Keller <m....@orcasoft.ch>.
Hello Dirk

dbrenck wrote:
> Any idea why the following query fails?
> 
> Serverside:
> 
>  pu for xxxx classes  TRACE  [ejbd 10] openjpa.Query - Executing query:
> [SELECT entity FROM TypeEntity entity WHERE ( entity.id = :id ) AND (
> entity.version = ( SELECT MAX( sameentity.version ) FROM TypeEntity
> sameentity WHERE sameentity.id = :id ))] with parameters: {id=1011}

As far as I know the @Version property is only made for 
optimistic locking in a multiple user environment. This 
property should only be used by the JPA and you should leave 
it alone.

 > Column 'id' and 'version' are primary-key columns (and
 > getter methods are
 > tagged @Id)

To define the @Version property as a primary-key column is 
not a good idea I think. You should use a more common way 
for your primary-keys.

Markus