You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by sbedoll <be...@us.ibm.com> on 2008/10/27 14:37:51 UTC

Native Query: Update fails with InvalidStateException

I am using local transactions and get this error when executing a NativeQuery
(query.executeUpdate)

<openjpa-1.0.1-r420667:592145 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: Cannot perform an
update or delete operation on select query: "Update FPA2.NW_OR_004_14702765
Set Cost=? Where PT_GRID_ID=?".
	at
org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:324)
	at
fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate(JPADataSourceAdapter.java:815)

I am using IBM JPA.  Is there something I am missing ?


-- 
View this message in context: http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Native Query: Update fails with InvalidStateException

Posted by sbedoll <be...@us.ibm.com>.


Fay Wang wrote:
> 
> Hi,
>    I could not reproduce this problem against DB2. Which database are you
> using? also,can you post your persistence.xml to see if there is any
> special setting?
> 
> Fay
> 
> --- On Mon, 10/27/08, sbedoll <be...@us.ibm.com> wrote:
> 
>> From: sbedoll <be...@us.ibm.com>
>> Subject: Native Query: Update fails with InvalidStateException
>> To: users@openjpa.apache.org
>> Date: Monday, October 27, 2008, 6:37 AM
>> I am using local transactions and get this error when
>> executing a NativeQuery
>> (query.executeUpdate)
>> 
>> <openjpa-1.0.1-r420667:592145 nonfatal user error>
>> org.apache.openjpa.persistence.InvalidStateException:
>> Cannot perform an
>> update or delete operation on select query: "Update
>> FPA2.NW_OR_004_14702765
>> Set Cost=? Where PT_GRID_ID=?".
>> 	at
>> org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:324)
>> 	at
>> fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate(JPADataSourceAdapter.java:815)
>> 
>> I am using IBM JPA.  Is there something I am missing ?
>> 
>> 
>> -- 
>> View this message in context:
>> http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html
>> Sent from the OpenJPA Users mailing list archive at
>> Nabble.com.
> 
> 
>       
> 
> 

-- 
View this message in context: http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1383529.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Native Query: Update fails with InvalidStateException

Posted by Stuart Bedoll <be...@us.ibm.com>.
great.. that worked.. thanks!


                                                                           
             Fay Wang                                                      
             <fyw300@yahoo.com                                             
             >                                                          To 
                                       users@openjpa.apache.org            
             10/28/2008 10:00                                           cc 
             PM                        fyw300@yahoo.com                    
                                                                   Subject 
                                       Re: Native Query: Update fails with 
             Please respond to         InvalidStateException               
             users@openjpa.apa                                             
                  che.org                                                  
                                                                           
                                                                           
                                                                           
                                                                           




Hi, Stuart,
      The error message "Cannot perform an update or delete operation on
select query" suggests that openjpa thinks your query is a select
operation, and therefore when executeUpdate is called on this query,
openjpa does not know how to update/delete on the select statement.

    There are a couple of reason why openjpa will think a query is a select
statement. The following is one example:

Query query  = em.createNativeQuery("update BasicA set name = ? where id
=?", BasicA.class);

Note that the result class (BasicA.class) is provided as an extra input
parameter to the createNativeQuery api. For this query object, if you call
executeUpdate on it, you will get "Cannot perform an update or delete
operation on select query" error. You might want to check your code to see
exactly how the native query is created.

Regards,
Fay





--- On Tue, 10/28/08, Stuart Bedoll <be...@us.ibm.com> wrote:
From: Stuart Bedoll <be...@us.ibm.com>
Subject: Re: Native Query: Update fails with InvalidStateException
To: users@openjpa.apache.org
Date: Tuesday, October 28, 2008, 1:06 PM


What version of the IBM feature pack did you use. I am at:



Name                     WebSphere Application Server Version 6.1 Feature
Pack for EJB 3.0

Version                  6.1.0.13

ID                       EJB3

Build Level              f0747.05

Build Date               11/30/07



Installed Product

Fay Wang <fy...@yahoo.com>











Fay Wang <fy...@yahoo.com>
10/27/2008 10:10 AM

Please respond to

users@openjpa.apache.org









To

users@openjpa.apache.org



cc





Subject

Re: Native Query: Update fails with InvalidStateException









Hi,

   I could not reproduce this problem against DB2. Which database are you
using? also,can you post your persistence.xml to see if there is any
special setting?



Fay



--- On Mon, 10/27/08, sbedoll <be...@us.ibm.com> wrote:



> From: sbedoll <be...@us.ibm.com>

> Subject: Native Query: Update fails with InvalidStateException

> To: users@openjpa.apache.org

> Date: Monday, October 27, 2008, 6:37 AM

> I am using local transactions and get this error when

> executing a NativeQuery

> (query.executeUpdate)

>

> <openjpa-1.0.1-r420667:592145 nonfatal user error>

> org.apache.openjpa.persistence.InvalidStateException:

> Cannot perform an

> update or delete operation on select query: "Update

> FPA2.NW_OR_004_14702765

> Set Cost=? Where PT_GRID_ID=?".

>                         at

> org.apache.openjpa.persistence.QueryImpl.executeUpdate
(QueryImpl.java:324)

>                         at

> fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate
(JPADataSourceAdapter.java:815)

>

> I am using IBM JPA.  Is there something I am missing ?

>

>

> --

> View this message in context:

>
http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html


> Sent from the OpenJPA Users mailing list archive at

> Nabble.com.













Re: Native Query: Update fails with InvalidStateException

Posted by Fay Wang <fy...@yahoo.com>.
Hi, Stuart,
      The error message "Cannot perform an update or delete operation on select query" suggests that openjpa thinks your query is a select operation, and therefore when executeUpdate is called on this query, openjpa does not know how to update/delete on the select statement.

    There are a couple of reason why openjpa will think a query is a select statement. The following is one example:

Query query  = em.createNativeQuery("update BasicA set name = ? where id =?", BasicA.class);

Note that the result class (BasicA.class) is provided as an extra input parameter to the createNativeQuery api. For this query object, if you call executeUpdate on it, you will get "Cannot perform an update or delete operation on select query" error. You might want to check your code to see exactly how the native query is created.

Regards,
Fay

 



--- On Tue, 10/28/08, Stuart Bedoll <be...@us.ibm.com> wrote:
From: Stuart Bedoll <be...@us.ibm.com>
Subject: Re: Native Query: Update fails with InvalidStateException
To: users@openjpa.apache.org
Date: Tuesday, October 28, 2008, 1:06 PM


What version of the IBM feature pack did you use. I am at:



Name                     WebSphere Application Server Version 6.1 Feature Pack for EJB 3.0

Version                  6.1.0.13

ID                       EJB3

Build Level              f0747.05

Build Date               11/30/07



Installed Product

Fay Wang <fy...@yahoo.com>











Fay Wang <fy...@yahoo.com> 
10/27/2008 10:10 AM

Please respond to

users@openjpa.apache.org









To

users@openjpa.apache.org



cc





Subject

Re: Native Query: Update fails with InvalidStateException









Hi,

   I could not reproduce this problem against DB2. Which database are you using? also,can you post your persistence.xml to see if there is any special setting?



Fay



--- On Mon, 10/27/08, sbedoll <be...@us.ibm.com> wrote:



> From: sbedoll <be...@us.ibm.com>

> Subject: Native Query: Update fails with InvalidStateException

> To: users@openjpa.apache.org

> Date: Monday, October 27, 2008, 6:37 AM

> I am using local transactions and get this error when

> executing a NativeQuery

> (query.executeUpdate)

> 

> <openjpa-1.0.1-r420667:592145 nonfatal user error>

> org.apache.openjpa.persistence.InvalidStateException:

> Cannot perform an

> update or delete operation on select query: "Update

> FPA2.NW_OR_004_14702765

> Set Cost=? Where PT_GRID_ID=?".

> 		 at

> org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:324)

> 		 at

> fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate(JPADataSourceAdapter.java:815)

> 

> I am using IBM JPA.  Is there something I am missing ?

> 

> 

> -- 

> View this message in context:

> http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html

> Sent from the OpenJPA Users mailing list archive at

> Nabble.com.





      






      

Re: Native Query: Update fails with InvalidStateException

Posted by Fay Wang <fy...@yahoo.com>.
Hi, Stuart,

   The error message "Cannot perform an update or delete operation on select query: "Update FPA2.NW_OR_004_14702765 Set Cost=? Where PT_GRID_ID=?"." suggests that openjpa thinks your native query is a select statement. The call to executeUpdate therefore can not be performed on a select statement. 

    There are a couple of reasons why openjpa thinks your query is a select statement. The following is an example (note the result class, BasicA.class, is an input paramter to the createNativeQuery api). An executeUpdate on it results in the same error as you describe:

        Query q = em.createNativeQuery("UPDATE BasicA t set t.name= ? WHERE t.id = ?", BasicA.class);

       The query below takes out the result class and works just fine:
        Query q = em.createNativeQuery("UPDATE BasicA t set t.name= ? WHERE t.id = ?"); 

Regards,
Fay






--- On Tue, 10/28/08, Stuart Bedoll <be...@us.ibm.com> wrote:
From: Stuart Bedoll <be...@us.ibm.com>
Subject: Re: Native Query: Update fails with InvalidStateException
To: users@openjpa.apache.org
Date: Tuesday, October 28, 2008, 1:06 PM


What version of the IBM feature pack did you use. I am at:



Name                     WebSphere Application Server Version 6.1 Feature Pack for EJB 3.0

Version                  6.1.0.13

ID                       EJB3

Build Level              f0747.05

Build Date               11/30/07



Installed Product

Fay Wang <fy...@yahoo.com>











Fay Wang <fy...@yahoo.com> 
10/27/2008 10:10 AM

Please respond to

users@openjpa.apache.org









To

users@openjpa.apache.org



cc





Subject

Re: Native Query: Update fails with InvalidStateException









Hi,

   I could not reproduce this problem against DB2. Which database are you using? also,can you post your persistence.xml to see if there is any special setting?



Fay



--- On Mon, 10/27/08, sbedoll <be...@us.ibm.com> wrote:



> From: sbedoll <be...@us.ibm.com>

> Subject: Native Query: Update fails with InvalidStateException

> To: users@openjpa.apache.org

> Date: Monday, October 27, 2008, 6:37 AM

> I am using local transactions and get this error when

> executing a NativeQuery

> (query.executeUpdate)

> 

> <openjpa-1.0.1-r420667:592145 nonfatal user error>

> org.apache.openjpa.persistence.InvalidStateException:

> Cannot perform an

> update or delete operation on select query: "Update

> FPA2.NW_OR_004_14702765

> Set Cost=? Where PT_GRID_ID=?".

> 		 at

> org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:324)

> 		 at

> fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate(JPADataSourceAdapter.java:815)

> 

> I am using IBM JPA.  Is there something I am missing ?

> 

> 

> -- 

> View this message in context:

> http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html

> Sent from the OpenJPA Users mailing list archive at

> Nabble.com.





      






      

Re: Native Query: Update fails with InvalidStateException

Posted by Stuart Bedoll <be...@us.ibm.com>.
What version of the IBM feature pack did you use. I am at:

Name                     WebSphere Application Server Version 6.1 Feature
Pack for EJB 3.0
Version                  6.1.0.13
ID                       EJB3
Build Level              f0747.05
Build Date               11/30/07

Installed Product


                                                                           
             Fay Wang                                                      
             <fyw300@yahoo.com                                             
             >                                                          To 
                                       users@openjpa.apache.org            
             10/27/2008 10:10                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re: Native Query: Update fails with 
             Please respond to         InvalidStateException               
             users@openjpa.apa                                             
                  che.org                                                  
                                                                           
                                                                           
                                                                           
                                                                           




Hi,
   I could not reproduce this problem against DB2. Which database are you
using? also,can you post your persistence.xml to see if there is any
special setting?

Fay

--- On Mon, 10/27/08, sbedoll <be...@us.ibm.com> wrote:

> From: sbedoll <be...@us.ibm.com>
> Subject: Native Query: Update fails with InvalidStateException
> To: users@openjpa.apache.org
> Date: Monday, October 27, 2008, 6:37 AM
> I am using local transactions and get this error when
> executing a NativeQuery
> (query.executeUpdate)
>
> <openjpa-1.0.1-r420667:592145 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException:
> Cannot perform an
> update or delete operation on select query: "Update
> FPA2.NW_OR_004_14702765
> Set Cost=? Where PT_GRID_ID=?".
>            at
> org.apache.openjpa.persistence.QueryImpl.executeUpdate
(QueryImpl.java:324)
>            at
> fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate
(JPADataSourceAdapter.java:815)
>
> I am using IBM JPA.  Is there something I am missing ?
>
>
> --
> View this message in context:
>
http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html

> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.




Re: Native Query: Update fails with InvalidStateException

Posted by Fay Wang <fy...@yahoo.com>.
Hi,
   I could not reproduce this problem against DB2. Which database are you using? also,can you post your persistence.xml to see if there is any special setting?

Fay

--- On Mon, 10/27/08, sbedoll <be...@us.ibm.com> wrote:

> From: sbedoll <be...@us.ibm.com>
> Subject: Native Query: Update fails with InvalidStateException
> To: users@openjpa.apache.org
> Date: Monday, October 27, 2008, 6:37 AM
> I am using local transactions and get this error when
> executing a NativeQuery
> (query.executeUpdate)
> 
> <openjpa-1.0.1-r420667:592145 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException:
> Cannot perform an
> update or delete operation on select query: "Update
> FPA2.NW_OR_004_14702765
> Set Cost=? Where PT_GRID_ID=?".
> 	at
> org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:324)
> 	at
> fpa.fw.ds.jpadataadapter.JPADataSourceAdapter.executeNativeUpdate(JPADataSourceAdapter.java:815)
> 
> I am using IBM JPA.  Is there something I am missing ?
> 
> 
> -- 
> View this message in context:
> http://n2.nabble.com/Native-Query%3A-Update-fails-with-InvalidStateException-tp1382362p1382362.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.