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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:59:43+00:00 2026-05-14T00:59:43+00:00

I try to optimize the database queries in Hibernate, but I found a blocker:

  • 0

I try to optimize the database queries in Hibernate, but I found a blocker:

<class name="SupportedLanguageVO" table="AR_SUPPORTED_LANG" >
    <cache usage="read-only"/>
 <id name="Id" type="java.math.BigInteger">
  <column name="ID" sql-type="NUMBER(20)" not-null="true"/>
  <generator class="assigned"/>
 </id>
    <property name="OrderSeq" type="java.math.BigInteger">
  <column name="ORDER_SEQ" sql-type="NUMBER(20)" not-null="true"/>
 </property>
    <many-to-one name="Country" class="CountryVO" column="CTRY_CD_ID" cascade="none" >
    <many-to-one name="Language" class="LanguageVO" column="LANG_CD" cascade="none" >

    </class>

The primary key of the Country is the CTRY_CD_ID. If I run the following criteria

  Criteria crit = m_Session.createCriteria(SupportedLanguageVO.class);
            crit.createCriteria("Country").add(Restrictions.eq("_CountryCode", p_countrycode));
            crit.addOrder(Order.asc("OrderSeq"));

I can see, that hibernate joins the ctry and the AR_SUPPORTED_LANG tables.
Why?
It would be better to run

select * from AR_SUPPORTED_LANG where ctry_cd_id=?

sql rather than

select * from AR_SUPPORTED_LANG inner join ctry .... where ctry_cd_id=?

Can I force hibernate to run the first query?

  • 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-14T00:59:43+00:00Added an answer on May 14, 2026 at 12:59 am

    Why? It would be better to run…

    That’s not necessarily true, and in fact depends heavily on how your database optimizes its queries. Generally speaking, inner joining will be more efficient because it has the opportunity to vastly reduce the search scope. Of course, with a simple type table with only a couple dozen rows it looks like overkill. Add a couple million rows and you’ll see the difference.

    For a similar reason, it’s generally optimal to add any query hints that you can to joins. For instance (rewriting your query in HQL):

    from AR_SUPPORTED_LANG inner join ctry c where c.cd_id=?
    

    …should be…

    from AR_SUPPORTED_LANG inner join ctry c WITH c.cd_id=?
    

    The WITH clause is an HQL-specific method of adding AND clauses to JOIN statements.

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

Sidebar

Related Questions

I'm in a try to optimize some cassandra queries which I use the row
I've found a number of resources that talk about tuning the database server, but
I get this error when I try recreate tables in my database with hibernate.
I try to optimize my pages by putting some async attributes on my scripts.
I would like to implement an B+ tree in Java and try to optimize
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
To optimize SELECT queries, I run them both with and without an index and
In my MySQL database I see these statistics: Type Usage Data 16,384 Bytes Index

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.