-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem on using LockMode.upgrade in named query inOracle DB
PostPosted: Mon Apr 30, 2007 10:37 am 
Newbie

Joined: Wed Jan 03, 2007 4:12 am
Posts: 11
Location: Singapore
Hi all,

I am using the pessimistic lock 'Upgrade' in my named query. However I encounter some sql grammar error while executing in Oracle DB. I have tested with Postgres DB and without error. The named query is listed below

Code:
<query name="getProcessTransByProUID"><![CDATA[FROM ProcessTransaction AS pt WHERE pt.processInstanceUID = :processInstanceUID]]></query>



below is subset of the code that prepare the named query and applying the LockMode.Upgrade

Code:

//From class ProcessTransactionDAO
public ProcessTransaction selectForUpdateProcessTrans(Long processUID)
  {
    String queryName = getPersistenceClass().getName()+".getProcessTransByProUID";
    String[] paramName = new String[]{"processInstanceUID"};
    Long[] paramValue = new Long[]{processUID};
   
    ProcessTransaction proTran = (ProcessTransaction)queryOneWithLock(queryName, paramName, paramValue, "pt", LockMode.UPGRADE);
    return proTran;
  }

//From class DAO
public Object queryOneWithLock(String queryName, String[] paramNames, Object[] paramVals, String alias, LockMode lockMode)
  {
    Query query = createQuery(queryName, paramNames, paramVals);
    if (query == null)
    {
      return null;
    }
    query.setMaxResults(1);
    query.setLockMode(alias, lockMode);
    return query.uniqueResult();
  }

//From class DAO
protected Query createQuery(String queryName, String[] paramNames, Object[] paramVals)
  {
    Query query = getCurrentSession().getNamedQuery(queryName);
    if (query == null)
    {
      System.err.println("Unable to find named query: "+queryName);
      return null;
    }
    if (paramNames != null && paramVals != null && paramNames.length<=paramVals.length)
    {
      for (int i=0; i<paramNames.length; i++)
      {
        query.setParameter(paramNames[i], paramVals[i]);
      }
    }

    return query;
  }


The error I encoutered was as followed

[30:04:07-22:02:55,242] [ INFO:STDOUT] [JMS SessionPool Worker-54] Hibernate: select * from ( select processtra0_."uid" as uid1_86_, processtra0_."version" as version2_86_, processtra0_."group_name" as group3_86_, processtra0_."customer_duns" as customer4_86_, processtra0_."customer_name" as customer5_86_, processtra0_."error_reason" as error6_86_, processtra0_."error_type" as error7_86_, processtra0_."partner_duns" as partner8_86_, processtra0_."partner_name" as partner9_86_, processtra0_."pip_name" as pip10_86_, processtra0_."pip_version" as pip11_86_, processtra0_."process_end_time" as process12_86_, processtra0_."process_id" as process13_86_, processtra0_."process_start_time" as process14_86_, processtra0_."process_status" as process15_86_, processtra0_."request_doc_no" as request16_86_, processtra0_."response_doc_no" as response17_86_, processtra0_."process_instance_uid" as process18_86_, processtra0_."is_process_success" as is19_86_, processtra0_."is_initiator" as is20_86_, processtra0_."user_tracking_id" as user21_86_ from GTVAN."isat_process_transaction" processtra0_ where processtra0_."process_instance_uid"=? ) where rownum <= ? for update of processtra0_."uid"
[30:04:07-22:02:55,242] [DEBUG:org.hibernate.loader.hql.QueryLoader] [JMS SessionPool Worker-54] bindNamedParameters() 14491 -> processInstanceUID [1]
[30:04:07-22:02:55,273] [DEBUG:org.hibernate.jdbc.AbstractBatcher] [JMS SessionPool Worker-54] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[30:04:07-22:02:55,273] [DEBUG:org.hibernate.jdbc.ConnectionManager] [JMS SessionPool Worker-54] aggressively releasing JDBC connection
[30:04:07-22:02:55,273] [DEBUG:org.hibernate.jdbc.ConnectionManager] [JMS SessionPool Worker-54] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
[30:04:07-22:02:55,289] [DEBUG:org.hibernate.util.JDBCExceptionReporter] [JMS SessionPool Worker-54] could not execute query [select processtra0_."uid" as uid1_86_, processtra0_."version" as version2_86_, processtra0_."group_name" as group3_86_, processtra0_."customer_duns" as customer4_86_, processtra0_."customer_name" as customer5_86_, processtra0_."error_reason" as error6_86_, processtra0_."error_type" as error7_86_, processtra0_."partner_duns" as partner8_86_, processtra0_."partner_name" as partner9_86_, processtra0_."pip_name" as pip10_86_, processtra0_."pip_version" as pip11_86_, processtra0_."process_end_time" as process12_86_, processtra0_."process_id" as process13_86_, processtra0_."process_start_time" as process14_86_, processtra0_."process_status" as process15_86_, processtra0_."request_doc_no" as request16_86_, processtra0_."response_doc_no" as response17_86_, processtra0_."process_instance_uid" as process18_86_, processtra0_."is_process_success" as is19_86_, processtra0_."is_initiator" as is20_86_, processtra0_."user_tracking_id" as user21_86_ from GTVAN."isat_process_transaction" processtra0_ where processtra0_."process_instance_uid"=?]
java.sql.SQLException: ORA-00904: "PROCESSTRA0_"."uid": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:911)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1121)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:962)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1243)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3459)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:236)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:780)
at util.db.DAO.queryOneWithLock(DAO.java:272)
at audit.dao.ProcessTransactionDAO.selectForUpdateProcessTrans(ProcessTransactionDAO.java:60)

As can be seen from the above stack trace, the select statement seem like something wrong so the exception java.sql.SQLException: ORA-00904: "PROCESSTRA0_"."uid": invalid identifier has been throwned. As can be seen below,

select * from ( select processtra0_."uid" as uid1_86_, processtra0_."version" as version2_86_, processtra0_."group_name" as group3_86_, processtra0_."customer_duns" as customer4_86_, processtra0_."customer_name" as customer5_86_, processtra0_."error_reason" as error6_86_, processtra0_."error_type" as error7_86_, processtra0_."partner_duns" as partner8_86_, processtra0_."partner_name" as partner9_86_, processtra0_."pip_name" as pip10_86_, processtra0_."pip_version" as pip11_86_, processtra0_."process_end_time" as process12_86_, processtra0_."process_id" as process13_86_, processtra0_."process_start_time" as process14_86_, processtra0_."process_status" as process15_86_, processtra0_."request_doc_no" as request16_86_, processtra0_."response_doc_no" as response17_86_, processtra0_."process_instance_uid" as process18_86_, processtra0_."is_process_success" as is19_86_, processtra0_."is_initiator" as is20_86_, processtra0_."user_tracking_id" as user21_86_ from GTVAN."isat_process_transaction" processtra0_ where processtra0_."process_instance_uid"=? ) where rownum <= ? for update of processtra0_."uid"

Is the way I use the pessismistic lock correct? If so , is it the problem on the Oracle version i am using now ?

The setup in my box is as followed
Hibernate 3.2 GA
Oracle 10g
Jboss 4.0.5 GA


Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 2:24 am 
Newbie

Joined: Wed Jan 03, 2007 4:12 am
Posts: 11
Location: Singapore
Hi all,

I removed the LockMode during query, and the select statement generated by hibernate is as followed. And the query is running fine in Oracle

select * from ( select processtra0_."uid" as uid1_86_, processtra0_."version" as version2_86_, processtra0_."group_name" as group3_86_, processtra0_."customer_duns" as customer4_86_, processtra0_."customer_name" as customer5_86_, processtra0_."error_reason" as error6_86_, processtra0_."error_type" as error7_86_, processtra0_."partner_duns" as partner8_86_, processtra0_."partner_name" as partner9_86_, processtra0_."pip_name" as pip10_86_, processtra0_."pip_version" as pip11_86_, processtra0_."process_end_time" as process12_86_, processtra0_."process_id" as process13_86_, processtra0_."process_start_time" as process14_86_, processtra0_."process_status" as process15_86_, processtra0_."request_doc_no" as request16_86_, processtra0_."response_doc_no" as response17_86_, processtra0_."process_instance_uid" as process18_86_, processtra0_."is_process_success" as is19_86_, processtra0_."is_initiator" as is20_86_, processtra0_."user_tracking_id" as user21_86_ from "isat_process_transaction" processtra0_ where processtra0_."process_instance_uid"=? ) where rownum <= ?


And compare with the one that i specify the lockmode.Upgrade

select * from ( select processtra0_."uid" as uid1_86_, processtra0_."version" as version2_86_, processtra0_."group_name" as group3_86_, processtra0_."customer_duns" as customer4_86_, processtra0_."customer_name" as customer5_86_, processtra0_."error_reason" as error6_86_, processtra0_."error_type" as error7_86_, processtra0_."partner_duns" as partner8_86_, processtra0_."partner_name" as partner9_86_, processtra0_."pip_name" as pip10_86_, processtra0_."pip_version" as pip11_86_, processtra0_."process_end_time" as process12_86_, processtra0_."process_id" as process13_86_, processtra0_."process_start_time" as process14_86_, processtra0_."process_status" as process15_86_, processtra0_."request_doc_no" as request16_86_, processtra0_."response_doc_no" as response17_86_, processtra0_."process_instance_uid" as process18_86_, processtra0_."is_process_success" as is19_86_, processtra0_."is_initiator" as is20_86_, processtra0_."user_tracking_id" as user21_86_ from "isat_process_transaction" processtra0_ where processtra0_."process_instance_uid"=? ) where rownum <= ? for update of processtra0_."uid"

I am not sure why the select statement generated by hibernate will reference the alias name (processtra0) in the internal select statement. pls see the text highlighted as bold

Could someone enlighten me ?

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 1:12 pm 
Newbie

Joined: Wed Jan 03, 2007 4:12 am
Posts: 11
Location: Singapore
I was able to resolve it by removing the setMaxResults(1) (see the method queryOneWithLock) while returning the result from the query

Does it means that the combination of setMaxResults and setLockMode during the select statement will not be working in Oracle 10g?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.