How to receive multiple scalar valuesin Hibernate

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.
prsubjectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurvinder Pal SinghCommented:
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
prsubjectAuthor Commented:
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
Gurvinder Pal SinghCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tango_1Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.