Solved

How to receive multiple scalar valuesin Hibernate

Posted on 2010-08-12
4
730 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now