-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need help for retrieving data using non primary key?
PostPosted: Mon Nov 02, 2009 1:49 am 
Newbie

Joined: Fri Sep 05, 2008 2:08 am
Posts: 7
Hello Friends,
I am developing on sample application using Struts 1.2, Hibernate 3.2 Oracle 9i, Weblogic 8.1
Table is EMP table in oracle.
My application main objective is To display emp data on JSP.
I have successfully done insert data, update data, delete data,retrieving (primary key).
I am not able to retrieve data using non primary key value(like mgr column in emp table).
My code is:
Code:
public List listMgrEmp(int mgr){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
   
        String qry ="from empBean.Employee as emp where emp.mgr= "+mgr;
   
        List result = session.createSQLQuery(qry).list();
   
        session.getTransaction().commit();
        System.out.println("exit from  listMgrEmp method");
        return result;
    }

When I tried to do I am getting below error:

Code:
[color=#FF0000]Nov 2, 2009 11:07:09 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 900, SQLState: 42000
Nov 2, 2009 11:07:09 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-00900: invalid SQL statement

org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.doList(Loader.java:2216)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
   at org.hibernate.loader.Loader.list(Loader.java:2099)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
   at DaoLayer.CMPEmpDao.listMgrEmp(CMPEmpDao.java:125)
   at StrutsController.EBEmpAction.execute(EBEmpAction.java:143)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
   at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
   at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
   at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Caused by: java.sql.SQLException: ORA-00900: invalid SQL statement

   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
   at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
   at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
   at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1983)
   at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1141)
   at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2149)
   at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2032)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2894)
   at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
   at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
   at org.hibernate.loader.Loader.doQuery(Loader.java:674)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.doList(Loader.java:2213)
   ... 24 more
returnPage....errorEmployeePage[/color]


Please help me in this regarding....

thanks in advance....
Sridhar


Top
 Profile  
 
 Post subject: Re: Need help for retrieving data using non primary key?
PostPosted: Fri Jun 17, 2011 9:46 am 
Newbie

Joined: Fri Jun 17, 2011 9:39 am
Posts: 1
sreedhar,

I had this same issue with Hiberate 3.0, but when running jUnit tests. I believe it has to do with the type of driver that you have installed. In my case it's Oracle and using the following:
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>

when I changed the following from "true" to "false":
<property name="hibernate.use_sql_comments">false</property>
<property name="hibernate.format_sql">false</property>

I was able to run the stored procedure successfully.

Hope this helps,
scott


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.