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