New to named SQL, using Hibernate 3.2.
I want to select one colum from TABLE_1 (e.g., COL_A), map it to attributeA of org.poc.MyObj.java and get the return type as org.poc.MyObj.java.
When I invoke the named SQL from the client Java code, I get error as:
[IBM][JDBC Driver] CLI0611E Invalid column name. SQLSTATE=S0022
I am using DB2 8.x. However, I can copy and paste the generated query and run successfully in DB2 8.x database editor and get the result back.
Following is the 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 package="org.poc" >
<sql-query name="myQuery">
<return alias = "my" class="org.poc.MyObj"/>
select T1.COL_A as {my.attributeA} FROM TABLE_1 as T1
</sql-query>
</hibernate-mapping>
If I remove <return class="MyObj"/>, then I get the result back from the calling Java client. However, that does not serve my purpose. I need the return type to be of type org.poc.MyObj.
Client Java code is:
Code:
Query query = session.getNamedQuery("myQuery");
List lst = query.list();
My intent is to write the query, as close as possible to SQL.
What am I missing?