-->
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: hibernate additional parameter in named query
PostPosted: Thu Apr 11, 2013 8:41 pm 
Newbie

Joined: Tue Apr 09, 2013 9:40 pm
Posts: 2
My hierarchy HBM file is as follows. When I do a findHierarchyQuery, I want to be able to return an additional parameter back to the service. For now, let's say I want to return count(1) as Count. I have an extra field called Count in my DTO which is not present in the Hierarchy table. I want to add a query which returns a Count along with the table contents. Just to reiterate, my DTO has 1 extra field called Count in addition to add the fields in the table. So if I want to add a query like

Code:
<query name="findHierarchyQuery">
  <![CDATA[
      Select Hierarchy h, count(1) as Count from Hierarchy h
    where h.code = :Code
  ]]>
</query>


How would I make sure that the Count from the query is being read by the DTO setter?

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="xxx.xxx.dto"
default-lazy="true">
<class name="Hierarchy" table="HIERARCHY"
    dynamic-update="true">
    <id name="id" column="HIERARCHYID" type="integer"
        unsaved-value="null">
        <generator class="native">
            <param name="sequence">HIERARCHYSEQ</param>
        </generator>
    </id>
    <version name="hibernateVersionId" column="VERSIONNUM"
        type="integer" />
    <property name="HierarchyLevel" column="HIERARCHYLEVEL"
        type="integer"/>
</class>

<query name="findHierarchyQuery">
  <![CDATA[
      from Hierarchy h
    where h.code = :Code
  ]]>
</query>


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.