Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:37:09+00:00 2026-06-12T17:37:09+00:00

I am using hibernate. I have written native SQL query and I would like

  • 0

I am using hibernate. I have written native SQL query and I would like to specify data type of one of the column as below.

sqlQuery.addScalar("NAME", STRING);

I am querying 5 columns and ID is one of the column among them. But if I use addScalar, it is not returning all the columns and is returning only NAME. the reason why I am specifying the column type is NAME column is of CHAR(10) in table but I want String type. How can I specify the datatype and get all the columns?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:37:10+00:00Added an answer on June 12, 2026 at 5:37 pm

    To avoid the overhead of using ResultSetMetadata, or simply to be more explicit in what is returned, one can use addScalar():

    sess.createSQLQuery("SELECT * FROM CATS")
     .addScalar("ID", Hibernate.LONG)
     .addScalar("NAME", Hibernate.STRING)
     .addScalar("BIRTHDATE", Hibernate.DATE)
    

    This query specified:

    the SQL query string
    
    the columns and types to return
    

    This will return Object arrays, but now it will not use ResultSetMetadata but will instead explicitly get the ID, NAME and BIRTHDATE column as respectively a Long, String and a Short from the underlying resultset. This also means that only these three columns will be returned, even though the query is using * and could return more than the three listed columns.

    Ref: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html#d0e13646

    So, in your case add 4 more addScalar() method, with its column name and Data type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using grails-groovy with Hibernate, I have a SQL query like this in
I have written a code like this to fetch data from database using HQL:
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I have a problem with a query using hibernate. The entity class EntityClass has
I'm using Hibernate 4.0.1.Final. I have a table with a unique constraint column …
I'm using Struts2, Spring, and Hibernate. I have written a simple Excel file called
I'm using hibernate for the data access layer, so i have to write HQL
I have an application written in Spring 3.0 hooked up using Hibernate to a
I am using HibernateTemplate and have one abstract class where i have written all
I have a webservice using Hibernate as DAL - using MySql with InnoDB. Since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.