Hi All,
Just having a problem running a simple native sql query.
I am using postgresql 7.3.6 and hibernate 2.1.4
When I use a HQL query it works fine.
Here is my mapping file.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="gprs.hibernate.MsgOut"
table="msg_out"
>
<id
name="msgId"
type="java.lang.Integer"
column="msg_id"
>
<generator class="sequence">
<param name="sequence">msg_out_msg_id</param>
</generator>
</id>
<property
name="waitFlag"
type="java.lang.String"
column="wait_flag"
not-null="true"
length="1"
/>
<property
name="tryNum"
type="int"
column="try_num"
not-null="true"
length="4"
/>
<property
name="inProcessFlag"
type="java.lang.String"
column="in_process_flag"
not-null="true"
length="1"
/>
<property
name="sentFlag"
type="java.lang.String"
column="sent_flag"
not-null="true"
length="1"
/>
<property
name="errorNum"
type="int"
column="error_num"
not-null="true"
length="4"
/>
<property
name="remoteName"
type="java.lang.String"
column="remote_name"
length="15"
/>
<property
name="ip"
type="java.lang.String"
column="ip"
length="15"
/>
<property
name="port"
type="java.lang.Integer"
column="port"
length="4"
/>
<property
name="msgBody"
type="java.lang.String"
column="msg_body"
length="4000"
/>
<property
name="createdDate"
type="java.sql.Date"
column="created_date"
length="4"
/>
<property
name="createdTime"
type="java.sql.Time"
column="created_time"
length="8"
/>
<property
name="sentDate"
type="java.sql.Date"
column="sent_date"
length="4"
/>
<property
name="sentTime"
type="java.sql.Time"
column="sent_time"
length="8"
/>
<property
name="retryCancelFlag"
type="java.lang.String"
column="retry_cancel_flag"
not-null="true"
length="1"
/>
<property
name="adminCancelFlag"
type="java.lang.String"
column="admin_cancel_flag"
not-null="true"
length="1"
/>
<property
name="readFlag"
type="java.lang.String"
column="read_flag"
not-null="true"
length="1"
/>
<!-- associations -->
</class>
</hibernate-mapping>
Here is my java code:
Code:
String sql = "SELECT {m}.* FROM MSG_OUT {m}";
List msgout = session.createSQLQuery(sql, "m", MsgOut.class).list();
for (Iterator it = msgout.iterator(); it.hasNext();) {
MsgOut msg = (MsgOut) it.next();
System.out.println(msg + "\n");
}
Here is the exception I get:
Code:
DEBUG 18:22:46 net.sf.hibernate.SQL [main] SELECT m.* FROM MSG_OUT m
DEBUG 18:22:46 net.sf.hibernate.impl.BatcherImpl [main] preparing statement
DEBUG 18:23:59 net.sf.hibernate.loader.Loader [main] processing result set
DEBUG 18:23:59 net.sf.hibernate.util.JDBCExceptionReporter [main] SQL Exception
The column name msg_id0_ not found.
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.findColumn(AbstractJdbc1ResultSet.java:528)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getInt(AbstractJdbc1ResultSet.java:358)
at net.sf.hibernate.type.IntegerType.get(IntegerType.java:18)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:352)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:203)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.loader.SQLLoader.list(SQLLoader.java:92)
at net.sf.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:3802)
at net.sf.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:52)
at hibernate.Tester.<init>(Unknown Source)
at hibernate.Tester.main(Unknown Source)
WARN 18:23:59 net.sf.hibernate.util.JDBCExceptionReporter [main] SQL Error: 0, SQLState: null
ERROR 18:23:59 net.sf.hibernate.util.JDBCExceptionReporter [main] The column name msg_id0_ not found.
DEBUG 18:23:59 net.sf.hibernate.impl.BatcherImpl [main] done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG 18:23:59 net.sf.hibernate.impl.BatcherImpl [main] closing statement
Code: