-->
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: Need help understanding Invalid Column Name error
PostPosted: Tue Feb 07, 2006 3:05 pm 
Newbie

Joined: Tue Feb 07, 2006 2:51 pm
Posts: 4
Hibernate version:
3.0
Mapping documents:

hibernate config -- some propeties have been left out for safety sake
all neccessary items are there
Code:
       <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property><property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <property name="hibernate.connection.provider_classs">org.hibernate.connection.C3P0ConnectionProvider</property>
        <property name="hibernate.cglib.use_reflection_optimizer">false</property><!-- <property name="hibernate.c3p0.acquire_increment">1</property> -->
            <property name="hibernate.c3p0.idle_test_period">200</property> <!-- seconds -->
            <property name="hibernate.c3p0.max_size">50</property>
            <property name="hibernate.c3p0.min_size">2</property>
            <property name="show_sql">true</property>
            <property name="hibernate.default_schema">hill</property>
            <property name="hibernate.cglib.use_reflection_optimizer">false</property>
            <property name="hibernate.use_sql_comments">false</property>

<!-- mapping files -->

<mapping resource="amts/valueObject/Cat.hbm.xml"/>


Cat.hbm.xml

Code:
<?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>
    <class name="amts.valueObject.Cat" table="CATS" dynamic update="true" dynamic-insert="true">
           <id name="id" type="java.lang.Long" column="ID">
               <generator class="identity"/>
                </id>
             
                <property name="color" type="java.lang.String" column="COLOR"/>
                <property name="sex" type="java.lang.String" />
                <!--<property name="birthdate" type="java.util.Date" />-->
                        <!--<property name="weight" type="java.lang.String" />-->
           </class>
<sql-query name="catsQuery">
    <return alias="cattable" class="amts.valueObject.Cat"/>
    <return-scalar type="java.lang.String" column="ID"/>
    select id, sex FROM hill.CATS cattable where cattable.id > :idValue
</sql-query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Collection col = new ArrayList();
      Collection typeCol = new ArrayList();
      TypeVO type = new TypeVO();
      Session session = HibernateUtil.currentSession();
      session.beginTransaction();
      Configuration cfg = new Configuration();
     
      try
      {
          //Criteria crit = session.createCriteria(Cat.class);
          //List lst = crit.list();
          //List lst = session.createSQLQuery("select cattable.ID from hill.CATS cattable").addEntity("cattable", Cat.class).list();
          List lst = session.getNamedQuery("catsQuery").setInteger("idValue",1).list();
          col = lst;
          //iterate over the list converting to type
          System.out.println("COL SIZE is: "+col.size());
}
      catch(HibernateException he)
      {
          he.printStackTrace();
          throw he;
      }


Full stack trace of any exception that occurs:
11:46:50,400 INFO [STDOUT] Hibernate: select id, sex FROM hill.CATS cattable where cattable.id > ?
11:46:50,432 WARN [JDBCExceptionReporter] SQL Error: 17006, SQLState: null
11:46:50,432 ERROR [JDBCExceptionReporter] Invalid column name
11:46:50,447 INFO [STDOUT] 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:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at amts.ejb.AdminSessionBean.fetchCats(AdminSessionBean.java:981)
at amts.businessObject.AdminFacade.fetchCats(AdminFacade.java:510)
at controllers.admin.TypeController.fetchCats(TypeController.java:247)
at org.apache.jsp.processPages.searches.processCodeLists_jsp._jspService(processCodeLists_jsp.java:266)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
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.getLong(OracleResultSet.java:1540)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getLong(NewProxyResultSet.java:2729)
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:759)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 42 more


Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
[STDOUT] Hibernate: select id, sex FROM hill.CATS cattable where cattable.id > ?


This select statement is running fine from TOAD. We are playing with hibernate to decide if we can port some projects over to hibernate. Problem is we have some very intense queries and thus far have not been able to use the createQuery, createSQLQuery, or getNamedQuery elements. Letting Hibernate generate the queries works just fine, but we cannot get it to run our own queries. Can someone point me in the right direction.
Thanks

_________________
Never get in a workin mans way...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 3:35 pm 
Newbie

Joined: Tue Feb 07, 2006 2:51 pm
Posts: 4
Here is 2 inserts for the database, just to show column names and data

Code:
INSERT INTO CATS ( ID, PARENT_ID, BIRTHDATE, WEIGHT, COLOR, SEX ) VALUES (
2, 2,  TO_Date( '02/02/2006 10:33:33 AM', 'MM/DD/YYYY HH:MI:SS AM'), '14', 'yellow'
, 'female');



INSERT INTO CATS ( ID, PARENT_ID, BIRTHDATE, WEIGHT, COLOR, SEX ) VALUES (
3, 1,  TO_Date( '02/01/2006 10:03:49 AM', 'MM/DD/YYYY HH:MI:SS AM'), '15', 'brown'
, 'male');

_________________
Never get in a workin mans way...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:23 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
Code:
select {cattable.id}, {cattable.sex} FROM hill.CATS cattable where {cattable.id} > :idValue


Your queries shoule look like above so that hibernate can generate appropriate column names.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:31 pm 
Newbie

Joined: Tue Feb 07, 2006 2:51 pm
Posts: 4
So here is the result after applying the{}

Code:
11:28:58,186 INFO  [STDOUT] Hibernate: select ID0_, sex0_0_ FROM hill.CATS cattable where ID0_ > ?
11:28:58,248 WARN  [JDBCExceptionReporter] SQL Error: 904, SQLState: 42000
11:28:58,248 ERROR [JDBCExceptionReporter] ORA-00904: "ID0_": invalid identifier

11:28:58,264 INFO  [STDOUT] org.hibernate.exception.SQLGrammarException: could not execute query


I thought the {} were optional or did I read the manual wrong? Anyhow I will search on this problem for a while and see what I can read up on.
Thanks for the help.

_________________
Never get in a workin mans way...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:35 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
Code:
selct cattable.ID as {cattable.id}, cattable.sex as {cattable.sex} FROM hill.CATS cattable where cattable.ID > :idValue


sould work. I think {} are optional only if both the property names and column names are exactly same.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:49 pm 
Newbie

Joined: Tue Feb 07, 2006 2:51 pm
Posts: 4
Tried that and some other variations, none are working... I think you have started me down a good road. Would you happen to know any online resources where i can read more about the {} and the substitutions that hibernate does with them?

_________________
Never get in a workin mans way...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:54 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
You might have already seen this. Reference manual has whole chapter dedicated to this.

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


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.