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

  • Home
  • SEARCH
  • 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 8622527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:04:41+00:00 2026-06-12T07:04:41+00:00

I have a chunk of java code which hard codes a hibernate disjunction query

  • 0

I have a chunk of java code which hard codes a hibernate disjunction query that looks like this

session = HibernateUtils.beginTransaction("outpatient");
        Criteria criteria = session.createCriteria(AugmentToken.class);
        session.beginTransaction();
        if (type == Constants.ICD9CPT) {
            criteria.add(Restrictions.disjunction()
                    .add(Restrictions.eq("codeType", "d"))
                    .add(Restrictions.eq("codeType", "p"))
                    .add(Restrictions.eq("codeType", "c")));
        } else if (type == Constants.EM) {
            criteria.add(Restrictions.disjunction()
                    .add(Restrictions.eq("codeType", "eros"))
                    .add(Restrictions.eq("codeType", "ehpi"))
                    .add(Restrictions.eq("codeType", "epe")));
        }

But this is not very elegant code. What I would like to do is pass an array of codetypes to a method, and dynamically construct the dijunction criteria. Every website I look at provides examples of disjunctive queries that look like the above, but this will not work for me because I don’t want to hard code the construction of the restriction for the criteria since the number of code types can vary.

How do I do this?

Thank you,

Elliott

  • 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-12T07:04:42+00:00Added an answer on June 12, 2026 at 7:04 am

    I think I figured this out. You create the disjunction as a variable, then sequentially add to it.
    Specifically:

     String [] codeTypes = new String[3];
     codeTyes[0]="d";
     codeTypes[1]="p";
     codetypes[2]="c";
     /* note the above would normally be passed into the method containing the code below */
     Criteria criteria = session.createCriteria(AugmentToken.class);
        session.beginTransaction();
     Disjunction disjunction = Restrictions.disjunction();
     for (int x = 0; x < codeTypes.length; x++ ) {
      disjucntion.add(Restrictions.eq("codeType",codeTypes[x]);
     }
     criteria.add(disjunction);
    

    I found the answer in Beginning Hibernate on page 214. The book is accessible from books.google.com.

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

Sidebar

Related Questions

If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
In my project I have two chunk of code which I would like to
We have a chunk of code something like this // semi-pseudo code def result
I have this chunk of javascript that's kind of hacked around from http://www.developphp.com/view.php?tid=1248 and
So I have a chunk of code that declares some classes, creates data, uses
I have got a chunk of code like for i in range(0, len(a)) b[i]
I have a fairly large chunk of code that produces/returns an arraylist of search
I have this code here, which get a plain text, and turns it to
I've been porting a big chunk of Java code to C++ and have had
I have a chunk of javascript that users can copy and paste to put

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.