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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:18:29+00:00 2026-06-05T21:18:29+00:00

I have search screen which has 10 fields and involves around 5 to 6

  • 0

I have search screen which has 10 fields and involves around 5 to 6 tables to get the result. I am writing a custom SQL query and appending where condition only when a value exists.

Can someone please suggest is this the right approach or any other better way.

I cannot use any plugins or additional APIs for my situation.

StringBuffer sqlQuery = new StringBuffer();
sqlQuery.append (" select member.* from member, customer, case where customer.status='A');
if(firstName != null)
sqlQuery.append("customer.firstName= :firstName");

if(caseid != null)
sqlQuery.append("case.caseid =:caseid");

SQLQuery queryObj = createSQLquery(sqlQuery.toString());
queryObj.list();

where as member, customer, case are actual tables.

UPDATE

when I am adding where condition to string buffer

if(caseid != null)
sqlQuery.append(" and case.caseid =:caseid");

and when queryObj is formed I am doing it as
if(caseid != null)
queryObj.setString("caseid", caseid);

is there better way to add after queryObj (to combine both)?

Thanks 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-06-05T21:18:30+00:00Added an answer on June 5, 2026 at 9:18 pm

    No, it’s not necessarily the right approach. SQL is not the query language of choice when using Hibernate. HQL should be preferred when possible. And Hibernate also has the Criteria API which has been designed precisely to build dynamic queries.

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

Sidebar

Related Questions

I have a .net application which includes search screen which has a panel with
I have a search results screen and in the results payload supplied I get
I have a lookup screen with 25 fields. When the user clicks the search
I have an asp.net search screen which displays the results in a new browser
I basically have a page which shows a processing screen which has been flushed
I have a search screen in my WPF application. The screen is implemented as
I have an ASP.NET page that contains two div's. Both have search fields and
hi i m trying to insert 's in SQL sever i have search on
Have a question regarding something which has been bugging me for some time now.I'm
Suppose I have a search screen that is intended for looking up items. There

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.