-->
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.  [ 1 post ] 
Author Message
 Post subject: Named SQL - result alias and class
PostPosted: Mon Aug 11, 2008 12:56 pm 
Newbie

Joined: Mon Feb 26, 2007 5:23 pm
Posts: 5
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.