Solved

How to receive multiple scalar valuesin Hibernate

Posted on 2010-08-12
4
739 Views
Last Modified: 2013-11-11
As I try to retrieve values Using Hibernate(a single table) It is repeating the same value multiple times. I want to try using retrun type as scalar values so I can retrieve the two columns I need(Ex val1, val2) and receive them in the dao class. How can I receive multiple scalar values, is something I am not aware of.
0
Comment
Question by:prsubject
  • 2
4 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33428023
can you specifically mention what is it that you want to fetch from database as individual value?

however, check the example given in this link for adding multiple columns as scalar values.
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html#d0e13646
0
 

Author Comment

by:prsubject
ID: 33429465
Let me say
Named Query
        <query name="validateAccount">
            <![CDATA[FROM  Acct a WHERE  a.acctNbr= :acctnum]]>
        </query>

DAO Class
DAO class was receiving the list of Acct objects. But this is returning the same value multiple times. So I wanted to return sclar values of Acct.siteSid and Acct.acctNum and receive the list of those two values. I also want to know how it would be even if it is not a list (Just these two values are to be returned). Thanks in advance.
Query query = session.getNamedQuery("com.temp.entity.Acct.validateAccount");
        query.setString("acctnum", acct);
        query.setString("siteID", siteID);
        accountList= query.list();
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 33453294
the link i have posted have an example of how to add multiple scalar values in the query.

Please try the same and let me know in case of any problem
0
 

Expert Comment

by:tango_1
ID: 35169457
You can use the concatenate operator (
||

Open in new window

for Oracle RDBMS] in your query to concatenate the columns. Then return just one scalar value as string. In your Java Code where you receive the list, you can iterate over the list and split on the delimiter (say a comma).

Please see the example named hibernate query below:
<sql-query name="eg.readGenreForTitleIDs">
      <return-scalar column="returnValue" type="java.lang.String"/>
        SELECT le.object_id || ',' || l.display_name AS returnValue
        FROM list_entry le, list l
        WHERE le.object_id IN (:titleIds)
        AND le.list_id = l.list_id
        AND l.list_type = 'GENRE'
        AND l.object_type = 'TITLE'
        ORDER BY le.object_id, l.display_name
    </sql-query> 

Open in new window


Be careful on selecting the delimiter though as it may throw your split function off.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 52
servlet web applications   metadata-complete="true" or false 3 201
intellij error 2 33
Eclipse for Java EE development 2 45
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question