-->
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.  [ 7 posts ] 
Author Message
 Post subject: Exception while using native sql
PostPosted: Thu Mar 02, 2006 7:25 am 
Newbie

Joined: Thu Mar 02, 2006 6:08 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


When i try to execute native sql query in hibernate i get the following exception, but same works with Query :


org.hibernate.exception.SQLGrammarException: could not execute query
at com.tcs.pdn.dataservices.order.dao.ORDQuartzDAO.rtrvCustomerRoles(ORDQuartzDAO.java:260)
at com.tcs.pdn.dataservices.order.dao.ORDQuartzDAO.main(ORDQuartzDAO.java:728)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:109)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1575)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:165)
at com.tcs.pdn.dataservices.order.dao.ORDQuartzDAO.rtrvCustomerRoles(ORDQuartzDAO.java:238)
... 1 more
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:625)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:661)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:893)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:693)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:988)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2884)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2925)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1676)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
... 7 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 7:35 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
please post your sql query and your mapping files

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 7:57 am 
Newbie

Joined: Thu Mar 02, 2006 6:08 am
Posts: 4
Query:

SQLQuery qry = HibernateUtil.currentSession().createSQLQuery(" select ordrPosType as ord from STOrderTO STO where "
+"STO.ordrStat in ( 1,2,3,15,16,29,41) "
+"and STO.instrumentId=4276");
qry.addScalar("ord",Hibernate.STRING);
result = qry.list();


mapping file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.tcs.pdn.to.order.STOrderTO" table="ST_ORDER" >
<id name="ordrId" type="integer">
<column name="ORDR_ID" precision="9" scale="0" not-null="true"/>
</id>
<property name="instrumentId" type="integer">
<column name="INSTRMNT_ID" precision="8" scale="0" />
</property>
<property name="ordrStat" type="integer">
<column name="ORDR_STAT" precision="2" scale="0" not-null="true" />
</property>
<property name="ordrPosType" type="integer">
<column name="ORDR_POS_TYPE" precision="4" scale="0" not-null="true" />
</property>


</class>
</hibernate-mapping>



java class:

package com.tcs.pdn.to.order;

import com.tcs.pdn.to.common.PDNBaseTO;



public class STOrderTO extends PDNBaseTO {


private Integer ordrId;
private Integer instrumentId;
private Integer ordrStat;
private Integer ordrPosType;



/** default constructor */
public STOrderTO() {
}



/**
* @return Returns the instrumentId.
*/
public Integer getInstrumentId() {
return instrumentId;
}
/**
* @param instrumentId The instrumentId to set.
*/
public void setInstrumentId(Integer instrumentId) {
this.instrumentId = instrumentId;
}
/**
* @return Returns the ordrId.
*/
public Integer getOrdrId() {
return ordrId;
}
/**
* @param ordrId The ordrId to set.
*/
public void setOrdrId(Integer ordrId) {
this.ordrId = ordrId;
}
/**
* @return Returns the ordrPosType.
*/
public Integer getOrdrPosType() {
return ordrPosType;
}
/**
* @param ordrPosType The ordrPosType to set.
*/
public void setOrdrPosType(Integer ordrPosType) {
this.ordrPosType = ordrPosType;
}
/**
* @return Returns the ordrStat.
*/
public Integer getOrdrStat() {
return ordrStat;
}
/**
* @param ordrStat The ordrStat to set.
*/
public void setOrdrStat(Integer ordrStat) {
this.ordrStat = ordrStat;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 8:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
damn this is funny ;)

why do you use the classname as the table name in a *native sql* query ?

...and why do you even do this query via createSQLQuery and not just via normal HQL ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 8:36 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Max is 100% right.

Maybe you wanna have a look at this:
http://www.hibernate.org/hib_docs/v3/re ... ryhql.html

and this:
http://www.hibernate.org/hib_docs/v3/re ... rysql.html

In general I would recommend to generally use HQL. If you can't do a query with HQL, native SQL is a good choice. Usually native SQL is being used for queries that *must* use database specific functions (for instance connect by in oracle).

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 12:59 am 
Newbie

Joined: Thu Mar 02, 2006 6:08 am
Posts: 4
i just gave a simple example.why i am using Sql is that i need to use decode function which i guess we dont have in HQL.

About writing the class instead of table i didnot know..
thanks for the help
Let me try :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 1:18 am 
Newbie

Joined: Thu Mar 02, 2006 6:08 am
Posts: 4
hey thanks..
its working


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