openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mitesh Meswani <Mitesh.Mesw...@Sun.COM>
Subject Re: OpenJPA error with NamedNativeQuery
Date Tue, 13 Mar 2007 18:22:57 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi John, <br>
<br>
&gt; EJB method calling is this:
<br>
&gt; public Quoteejb testForUpdateQuery(String symbol){
<br>
&gt; Query q = em.createNativeQuery("quoteForUpdate");
<br>
&gt; q.setParameter(1,symbol);
<br>
Shouldn't you call Query q = em.create<strike>Native</strike><u>Named</u>Query("quoteForUpdate");&nbsp;
?<br>
<br>
Regards,<br>
Mitesh<br>
<br>
Marc Prud'hommeaux wrote:
<blockquote cite="mid6202A0C0-D7F0-49D1-9EB3-D769240C4FE3@apache.org"
 type="cite">John-
  <br>
  <br>
I just ran a test with a named native query that did a "select ... for
update" and it worked fine.
  <br>
  <br>
One possibility is that our identification of whether the native query
is a select or an update is done by some fairly simplistic parsing of
whether the statement starts with "select" or not. Is it possible there
is some extra hidden character in the string? If you delete the
NamedNativeQuery line and re-type it, do you still get the same error?
  <br>
  <br>
If that doesn't help, can we try to narrow down the problem by
bypassing the named query and trying to just execute the query
directly? E.g., do the following:
  <br>
  <br>
em.createNativeQuery("select * from quoteejb q where q.symbol=? for
update").setParameter(1, "SYMBOL").getResultList();
  <br>
  <br>
  <br>
  <br>
On Mar 13, 2007, at 11:03 AM, John Stecher wrote:
  <br>
  <br>
  <blockquote type="cite">Marc,
    <br>
I know that we recompiled the classes multiple times and I also know
that the query is a correct/working for DB2 when running in a JDBC
environment.&nbsp; The statement never started with update.&nbsp; I wouldn't
expect that OpenJPA would be attempting to dictate what type of query I
am running in a native sql statement by it syntax.&nbsp;&nbsp; How are others
doing this select for update on a finder?&nbsp; A pure update doesn't work
as it would not allow me to hold the lock on the database.&nbsp; Patrick had
said that this should work with Kodo in our benchmarking disucssion (as
did Mike Keith for Toplink) so I am interested to see if it is in some
manner working with a test case that I am not privy to.
    <br>
    <br>
Any help would be greatly appreciated as I believe this is a gating
factor for us moving forward testing the SPEC benchmarks as well as
DayTrader being developed for Apache.
    <br>
    <br>
John
    <br>
    <br>
On 3/13/07, Marc Prud'hommeaux <a class="moz-txt-link-rfc2396E" href="mailto:mprudhom@apache.org">&lt;mprudhom@apache.org&gt;</a>
wrote:
    <br>
I am fairly certain that the only way OpenJPA will ever think that a
    <br>
native (i.e., SQL) query is not a select query is if it doesn't start
    <br>
with "select".
    <br>
    <br>
Is it possible that you didn't recompile the class after
    <br>
experimenting with the "quoteForUpdate" @NamedNativeQuery? At some
    <br>
point in the past, did the query string start with "update"?
    <br>
    <br>
    <br>
    <br>
On Mar 13, 2007, at 8:25 AM, Kevin Sutter wrote:
    <br>
    <br>
&gt; Hi,
    <br>
&gt; John is having some problems with posting to the open-jpa-dev
    <br>
&gt; mailing list
    <br>
&gt; via his e-mail account, so I am posting this message for him so
    <br>
&gt; that we can
    <br>
&gt; start this conversation...
    <br>
&gt;
    <br>
&gt; =================================================
    <br>
&gt;
    <br>
&gt; Fellow OpenJPAers, :)
    <br>
&gt;
    <br>
&gt; As Craig had brought up (through Scott Oaks) a while ago and
    <br>
&gt; Patrick was
    <br>
&gt; privy to on a discussion with a benchmarking organization we
needed a
    <br>
&gt; mechanism to implement pessimistic locking in some fashion under
    <br>
&gt; certain
    <br>
&gt; circumstances inside of our current optimistic world.&nbsp; We decided
    <br>
&gt; at that
    <br>
&gt; time that the only really portable way to do this at the moment
was to
    <br>
&gt; create a named query in the benchmark that could then be
overridden
    <br>
&gt; in the
    <br>
&gt; ORM.xml file.&nbsp; Well I took that at face value and started pushing
the
    <br>
&gt; methodology on the folks working on DayTrader for Apache and today
    <br>
&gt; we found
    <br>
&gt; out that you cannot issue a select for update query with either
the
    <br>
&gt; Oracle
    <br>
&gt; Toplink RI or OpenJPA 0.9.7-inc builds at this time.&nbsp; Maybe I am
just
    <br>
&gt; missing something in our approach but we decided to leave out the
    <br>
&gt; ORM.xmlmapping and just use a native named query in the code for
    <br>
&gt; DayTrader just to
    <br>
&gt; get it off the ground and running.&nbsp; Code snipit below:
    <br>
&gt;
    <br>
&gt; Native named Query defined as this:
    <br>
&gt; @NamedNativeQueries({
    <br>
&gt; @NamedNativeQuery(name="quoteForUpdate", query="select * from
    <br>
&gt; quoteejb q
    <br>
&gt; where q.symbol=? for update",resultClass=
    <br>
&gt; org.apache.geronimo.samples.daytrader.Quoteejb.class)
    <br>
&gt; })
    <br>
&gt;
    <br>
&gt; EJB method calling is this:
    <br>
&gt; public Quoteejb testForUpdateQuery(String symbol){
    <br>
&gt; Query q = em.createNativeQuery("quoteForUpdate");
    <br>
&gt; q.setParameter(1,symbol);
    <br>
&gt; //Quoteejb temp = (Quoteejb) q.getSingleResult();
    <br>
&gt; Quoteejb temp = (Quoteejb) q.getResultList().get(0);
    <br>
&gt; temp.setCompanyname("IBM_"+System.currentTimeMillis());
    <br>
&gt; return em.merge(temp);
    <br>
&gt; }
    <br>
&gt;
    <br>
&gt; This code produces the following errors on Toplink and on OpenJPA
    <br>
&gt;
    <br>
&gt; Toplink:
    <br>
&gt; Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8
(Build
    <br>
&gt; 060830)): oracle.toplink.essentials.exceptions.DatabaseException
    <br>
&gt; Internal Exception: com.ibm.db2.jcc.c.SqlException :
    <br>
&gt; [ibm][db2][jcc][10103][10941] Method executeQuery cannot be used
for
    <br>
&gt; update.Error Code: -99999
    <br>
&gt; Call:quoteForUpdate
    <br>
&gt; Query:DataReadQuery()
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.exceptions.DatabaseException.sqlException (
    <br>
&gt; DatabaseException.java:303)
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.bas
    <br>
&gt; icExecuteCall
    <br>
&gt; (DatabaseAccessor.java:551)
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.exe
    <br>
&gt; cuteCall
    <br>
&gt; (DatabaseAccessor.java:437)
    <br>
&gt; at oracle.toplink.essentials.threetier.ServerSession.executeCall(
    <br>
&gt; ServerSession.java:465)
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryM
    <br>
&gt; echanism.executeCall
    <br>
&gt; (DatasourceCallQueryMechanism.java:213)
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryM
    <br>
&gt; echanism.executeCall
    <br>
&gt; (DatasourceCallQueryMechanism.java :199)
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryM
    <br>
&gt; echanism.executeSelectCall
    <br>
&gt; (DatasourceCallQueryMechanism.java:270)
    <br>
&gt; at
    <br>
&gt;
oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryM
    <br>
&gt; echanism.executeSelect
    <br>
&gt; (DatasourceCallQueryMechanism.java:252)
    <br>
&gt;
    <br>
&gt; OpenJPA:Caused by: &lt;4|false|0.9.7-incubating-SNAPSHOT&gt;
    <br>
&gt; org.apache.openjpa.persistence.InvalidStateException: Cannot
perform a
    <br>
&gt; select on update or delete query: "quoteForUpdate".
    <br>
&gt; at
org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:
    <br>
&gt; 215)
    <br>
&gt; at org.apache.openjpa.persistence.QueryImpl.getResultList
    <br>
&gt; (QueryImpl.java
    <br>
&gt; :264)
    <br>
&gt; at
    <br>
&gt;
com.ibm.performance.primitives.jee5.ejb.QuoteejbFacade.testForUpdateQu
    <br>
&gt; ery
    <br>
&gt; (QuoteejbFacade.java:62)
    <br>
&gt; at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    <br>
&gt; at sun.reflect.NativeMethodAccessorImpl.invoke
    <br>
&gt; (NativeMethodAccessorImpl.java
    <br>
&gt; :39)
    <br>
&gt; at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    <br>
&gt; DelegatingMethodAccessorImpl.java :25)
    <br>
&gt; at java.lang.reflect.Method.invoke(Method.java:585)
    <br>
&gt; at
    <br>
&gt;
com.sun.enterprise.security.application.EJBSecurityManager.runMethod(
    <br>
&gt; EJBSecurityManager.java:1050)
    <br>
&gt; at com.sun.enterprise.security.SecurityUtil.invoke
    <br>
&gt; (SecurityUtil.java:165)
    <br>
&gt; at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(
    <br>
&gt; BaseContainer.java:2766)
    <br>
&gt; at com.sun.ejb.containers.BaseContainer.intercept
    <br>
&gt; (BaseContainer.java :3847)
    <br>
&gt; at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(
    <br>
&gt; EJBLocalObjectInvocationHandler.java:184)
    <br>
&gt; ... 30 more
    <br>
&gt;
    <br>
&gt; This query works perfectly fine in a straight up JDBC case so I
    <br>
&gt; can't see
    <br>
&gt; why it wouldn't work here.
    <br>
&gt;
    <br>
&gt; Looking forward to any responses.&nbsp; Would be happy if it was
    <br>
&gt; something the
    <br>
&gt; folks building DayTrader were doing wrong with the code but I
think
    <br>
&gt; it might
    <br>
&gt; be a OpenJPA issue.
    <br>
&gt;
    <br>
&gt; Sincerely,
    <br>
&gt; John
    <br>
    <br>
    <br>
  </blockquote>
  <br>
</blockquote>
</body>
</html>

Mime
View raw message