-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using named sql-query, Invalid Column Name, Oracle
PostPosted: Sun Apr 23, 2006 5:28 am 
Newbie

Joined: Sun Apr 23, 2006 5:01 am
Posts: 2
Hey! I've never used sql-queries in Hibernate before, and have come up with the following problem. I am using Oracle 9i RDBMS and Hibernate 3.1 and really need Oracle's CONNECT BY structure. I really hope that you can help. Thank you very much in advance.

Hibernate version:
3.1
Mapping documents:
<hibernate-mapping schema="KGTU">
<class name="einstein.model.POJO.EPlan" table="U_PLAN_LIST">
<id name="ID_PLAN_LIST" column="ID_PLAN_LIST">
<generator class="sequence">
<param name="sequence">SEQ_PLAN</param>
</generator>
</id>
<property name="KOD_GEN"/>
<many-to-one
name="speciality"
fetch="join"
class="einstein.model.POJO.Speciality"
column="ID_SPEC_LIST"/>
<many-to-one
name="FORMA"
fetch="join"
class="einstein.model.POJO.EForm"
column="FORMA"/>
<property
name="NAPRAV"
type="string"/>
<property
name="SPECZ"
type="string"/>
<many-to-one
name="department"
class="einstein.model.POJO.Department"
column="ID_DEPT_LIST"
fetch="join"/>
<set
name="courses"
inverse="true"
cascade="all,delete-orphan"
order-by="ID_DEPT">
<key column="ID_PLAN_LIST"/>
<one-to-many class="einstein.model.POJO.EPlanDet"/>
</set>
</class>

<sql-query name="ePlanByDepartment">
<return alias="u_plan_list" class="einstein.model.POJO.EPlan"/><![CDATA[
SELECT u_plan_list.ID_PLAN_LIST {u_plan_list.ID_PLAN_LIST}
FROM kgtu.u_plan_list u_plan_list
WHERE u_plan_list.id_dept_list in (select id_dept from kgtu.dept_list CONNECT BY PRIOR id_dept = id_dept_parent START WITH id_dept = :id)
]]>
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Query query = session.getNamedQuery("ePlanByDepartment");
list = query.setLong("id", deptId).list();
Full stack trace of any exception that occurs:
Hibernate: SELECT u_plan_list.ID_PLAN_LIST ID1_13_0_
FROM kgtu.u_plan_list u_plan_list
WHERE u_plan_list.id_dept_list in (select id_dept from kgtu.dept_list CONNECT BY PRIOR id_dept = id_dept_parent START WITH id_dept = ?)
(util.JDBCExceptionReporter 71 ) SQL Error: 17006, SQLState: null
(util.JDBCExceptionReporter 72 ) Invalid Column Name
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
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:1475)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:168) ....

Caused by: java.sql.SQLException: Invalid Column Name
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:5971)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1527)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1528)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:1898)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1372)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1300)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)

Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
The generated sql executes perfect from the Oracle, but I cannot get it work through the Hibernate API.

SELECT u_plan_list.ID_PLAN_LIST ID1_13_0_
FROM kgtu.u_plan_list u_plan_list
WHERE u_plan_list.id_dept_list in (select id_dept from kgtu.dept_list CONNECT BY PRIOR id_dept = id_dept_parent START WITH id_dept = ?)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 6:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you only return one column - doesn't your EPlan consists of more than those columns ?

and are you sure you are not just looking for querying scalar values ? (return-scalar)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 12:24 pm 
Newbie

Joined: Sun Apr 23, 2006 5:01 am
Posts: 2
max wrote:
you only return one column - doesn't your EPlan consists of more than those columns ?

and are you sure you are not just looking for querying scalar values ? (return-scalar)


Hello max! Thank you very much for your speedy reply. Yes, that's correct, EPlan has more then one column. Does that mean that in order to return EPlan object I need to set all of its properties? As I understand this is how it should be. Please confirm it. Thank you very much!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 2:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
of course you need to return all defining properties of an entity to get an entity - otherwise it is not an entity ;)

_________________
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.  [ 4 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.