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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:13:36+00:00 2026-05-24T06:13:36+00:00

I think this is a simple question although I do not know how to

  • 0

I think this is a simple question although I do not know how to solve it.

In a spring/Hibernate application I need to show the query that a criteria execute.

I know that I can use show_sql property and log the queries using log4j or any other logging framework but what I need is a higher level of logging.

I have a method like this

public void searchIntegrationClient(IntegrationClientSearchCommand integrationClientSearchCommand,PartialList<IntegrationClient> partialList) {
    Session session = getSession();
    Criteria pageCriteria=session.createCriteria(IntegrationClient.class);
    if(StringUtil.isNotEmpty(integrationClientSearchCommand.getNameCmd())){
        pageCriteria.add(Restrictions.like("name", integrationClientSearchCommand.getNameCmd(), MatchMode.START));
    }

    //adding ordering alphabetically
    pageCriteria.addOrder(Order.asc("name"));


    pageCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    List<IntegrationClient> list = (List<IntegrationClient>)pageCriteria.list();
    partialList.setPartialResultList(list);
    Criteria countCriteria=session.createCriteria(IntegrationClient.class);
    if(StringUtil.isNotEmpty(integrationClientSearchCommand.getNameCmd())){
        countCriteria.add(Restrictions.like("name", integrationClientSearchCommand.getNameCmd(), MatchMode.START));
    }
    countCriteria.setProjection(Projections.rowCount());
    partialList.setTotalNumberOfRecords(((Integer)countCriteria.uniqueResult()).intValue());

    releaseSession(session);
}

I need before executes the criteria.list to show the query that will be executed?

Is there any utility class in the criteria api to show the query like what I want ?

Thnx in advance

  • 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-24T06:13:38+00:00Added an answer on May 24, 2026 at 6:13 am

    I don’t know about any utility class in the JPA Criteria API. But there is the possibility of showing the SQL statements on the hibernate persistence level.

    Add the following line to your persistence.xml file:

       <properties>
          <property name="hibernate.show_sql" value="true" />
       </properties>
    

    If you are using log4j you can also set the logging level of org.hibernate.type to TRACE, which will show you even more verbose information in your logs. Add these lines to your log4j-config (you need to have some adapter called ‘FILE’ of course):

    <category name="org.hibernate.type">
        <priority value="TRACE"/>
        <appender-ref ref="FILE"/>
    </category>
    

    I hope this helps…

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

Sidebar

Related Questions

I think this is a simple question, but I can not find the answer
I think this is a simple question. How do I disable copy from a
i think this is a simple question but I've searched around and can't seem
I think this is a pretty simple question. How do you an apache rewrite
[see later answer for more] I think this is just a simple rails question,
This is a simple question I think. I am trying to search for the
I'm hoping this question has a very simple answer. I can think of ways
I think its quite a simple question but not sure. I have a class:
Please note that although it sounds similar, this is not the common how to
In Windows, that is. I think the answer to this question is that I

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.