-->
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.  [ 8 posts ] 
Author Message
 Post subject: Hibernate Query --
PostPosted: Mon May 02, 2005 5:48 pm 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
I am trying to execute the following piece of code, but hibernate reports an sql exception.

But when i execute the hibernate generated sql query in oracle, it works fine.
Any thoughts highly appreciated.

Hibernate version:
Hibernate 3.0.1
Mapping documents:
<?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 package="com.starwood.valhalla.inventory.hibernate.schema">

<class name="SleepingRoomProduct" table="PROP_PRDT_SLPG_RM">

<id name="propPrdtId">
<column name="PROP_PRDT_ID" length="15" not-null="true"/>
</id>


<property name="slpgRmDfltInvBaseQty">
<column name="SLPG_RM_DFLT_INV_BASE_QTY" length="9" not-null="false" />
</property>
</class>

</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
String propPrdSlpgRmSql ="select " +
"p.SLPG_RM_DFLT_INV_BASE_QTY as {obj.slpgRmDfltInvBaseQty} " +
"from PROP_PRDT_SLPG_RM p " +
"where p.PROP_PRDT_ID=:propPrdtId ";

SQLQuery propPrdSlpRoomQry = session.createSQLQuery(propPrdSlpgRmSql);
propPrdSlpRoomQry.addEntity("obj",SleepingRoomProduct.class);
propPrdSlpRoomQry.setLong("propPrdtId",productVO.getProductID().productidPK);

Full stack trace of any exception that occurs:
Hibernate: select p.SLPG_RM_DFLT_INV_BASE_QTY as SLPG2_1_0_ from PROP_PRDT_SLPG_RM p where p.PROP_PRDT_ID=?

May 2, 2005 5:47:27 PM org.hibernate.util.JDBCExceptionReporter
WARNING: SQL Error: 17006, SQLState: null
May 2, 2005 5:47:27 PM org.hibernate.util.JDBCExceptionReporter
SEVERE: Invalid column name
e: could not execute query
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1518)
at org.hibernate.loader.Loader.list(Loader.java:1498)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1340)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151)
at com.starwood.valhalla.inventory.dao.ProductHibernateDAO.getSleepingRoomProduct(ProductHibernateDAO.java:497)
at com.starwood.valhalla.inventory.dao.ProductHibernateDAO.getProductDetails(ProductHibernateDAO.java:94)
at com.starwood.valhalla.inventory.dao.ProductHibernateDAO.main(ProductHibernateDAO.java:572)
Caused by: java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:3047)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1861)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1617)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:691)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:280)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.doList(Loader.java:1515)
... 7 more
Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 7:41 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
message is clear : invalid column name - it isn't hibernate problem
You haven't column SLPG_RM_DFLT_INV_BASE_QTY or column PROP_PRDT_ID
in table PROP_PRDT_SLPG_RM
maybe you set wrong schema (username) in cfg file


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 9:57 am 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
hi snpesnpe,

In that case hibernate generated query works on sql editor.

If the configuration file is wrong then the generated sql file also
should be wrong is it???


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 11:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Um, addEntity() takes an entity (i.e. an instance of an entity). Not a class.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 2:00 pm 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
It does expects a class.
By the way what do you mean by entity in the current context
Please clarify


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 2:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
steve wrote:
Um, addEntity() takes an entity (i.e. an instance of an entity). Not a class.


addEntity expects a alias name and a class or entity-name ..not an instance of an entity.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 5:06 pm 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
I tried that too, still the same....


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 5:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
go look at the doc for native sql queries.

you need to return ALL columns for a given entity/class when using addEntity.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.