• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 757
  • Last Modified:

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.
  • 2
1 Solution
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.
prsubjectAuthor Commented:
Let me say
Named Query
        <query name="validateAccount">
            <![CDATA[FROM  Acct a WHERE  a.acctNbr= :acctnum]]>

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();
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
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

Open in new window

Be careful on selecting the delimiter though as it may throw your split function off.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now