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 1005951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:22:46+00:00 2026-05-16T08:22:46+00:00

When run against and Oracle database, what is the runtime type of the object

  • 0

When run against and Oracle database, what is the runtime type of the object that the following Spring Hibernate Template (Spring 2.5 and Hibernate 3.3.2GA) code returns where the SQL query is a counting query like select count(*) from table?

 String sql = "select count(*) from table";
 BigDecimal count = (BigDecimal) hibernateTemplate.execute(
   new HibernateCallback() { 
    public Object doInHibernate(Session session) throws HibernateException {
     SQLQuery query = session.createSQLQuery(sql);
     return (BigDecimal) query.uniqueResult();
    }});
 return count;

This code throws the following exception:

javax.ejb.EJBException: EJB Exception: : java.lang.ClassCastException: java.math.BigDecimal cannot be cast to [Ljava.lang.Object;
    at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83)
    at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2185)
    at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2129)
    at org.hibernate.loader.Loader.list(Loader.java:2087)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:804)
    at com.db.abstrack.dao.hibernate.RfqCdoUsDaoHibernate$1.doInHibernate(RfqCdoUsDaoHibernate.java:124)
  • 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-05-16T08:22:46+00:00Added an answer on May 16, 2026 at 8:22 am

    Turns out that the ClassCastException may be due to a bug in the Hibernate standard query cache.

    Solution is to add a scalar to the query:

    String sql = "select count(*) as result from table";
    BigDecimal count = (BigDecimal) ht.execute(new HibernateCallback() {
        public Object doInHibernate(Session session)
                throws HibernateException {
            SQLQuery query = session.createSQLQuery(sql);
            // Add scalar to avoid bug in Hibernate query cache.
            query.addScalar("result", Hibernate.BIG_DECIMAL);
            return query.uniqueResult();
        }
    });
    

    References:

    • ClassCastException with SQLQuery and setCacheable(true)
    • Martin Schaaf’s Blog: ClassCastException with SQLQuery and setCacheable(true)
    • Caching a raw sql count with Hibernate and EhCache
    • HHH-5163 Bug when applying a ResultTransformer on a cacheable projection based criteria
    • ClassCastException when Hibernate tries to cache results using ResultTransformer
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any good scripts that I could run against my Oracle database to
We have an Oracle database server specifically for our unit tests to run against.
I'm writing some code that needs to work against an array of different database
I have a web service (JAX-RS/Spring) that generates SQL queries which run against a
I have a number of tests that run against a MySQL database which is
I've written some integration tests that I'd like to run against a copy of
During our build process we run aspnet_compiler.exe against our websites to make sure that
I have a series of functional tests against a web application that correctly run,
Does anybody know what's going on here: I run hibernate 3.2.6 against a PostgreSQL
As part of our ANT based deploys we run some sql against an Oracle

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.