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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:32:31+00:00 2026-05-12T09:32:31+00:00

I want to use a standard deviation projection in a query that Im constructing

  • 0

I want to use a standard deviation projection in a query that Im constructing using the criteria API. I can do something simply like this

public class StdDevProjection extends AggregateProjection {

    public StdDevProjection(String propertyName) {
        super("stddev", propertyName);
    }

    public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
    throws HibernateException {
        return new Type[] { Hibernate.DOUBLE };
   }

}

and then I can use it with my criteria as:

myCriteriea.setProjection(new StdDevProjection(myproperty));

Thats all good. But my problem is that I use HSQLDB for any db unit tests etc, whereas we use Oracle for deployment. The stddev function works perfectly in oracle, but its not there in HSQLDB. HSQLDB has stddev_pop and stddev_samp . So is there someway I can use a different function based on the dialect.

I maybe can extend the HSQL dialect to register the “stddev” to the appropriate HSQL function, but then im not sure how to use an hsql function in a query constructed using the Criteria API.

Any help would be gret.

Thanks

  • 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-12T09:32:31+00:00Added an answer on May 12, 2026 at 9:32 am

    Using the dialect is the right approach (although I’ve got to say that using different database engines for testing vs deployment seems a bit iffy). You can do the following:

    1. Extend HSQL dialect and use registerFunction() to register an appropriate stddev implementation.
    2. Override toSqlString() method in your StdDevProjection class and have Dialect render function name.

    Something like:

    public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException {
      Dialect dialect = criteriaQuery.getFactory().getDialect();
      SQLFunction function = (SQLFunction) dialect.getFunctions().get(this.aggregate);
      //TODO: throw an exception if function is not registered
    
      //create function argument array
      List functionArgs = new ArrayList(1);
      functionArgs.add(criteriaQuery.getColumn(criteria, propertyName));
    
      return new StringBuffer()
        .append(function.render(functionArgs, criteriaQuery.getFactory()))
        .append(" as y").append(loc).append('_')
        .toString();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 307k
  • Answers 307k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I never tried it, but the arguments are contained in… May 13, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer Using :include => :chapters should fetch it all back resulting… May 13, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer You could probably use a Closure, to do just that...… May 13, 2026 at 9:26 pm

Related Questions

Is there any way to randomly generate a set of positive numbers such that
What's the rationale behind the formula used in the hive_trend_mapper.py program of this Hadoop
Not infrequently, one wants to implement the <=> (comparison, or spaceship) operator on a
I have a set of html files that I want to modify by replacing

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.