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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:09:33+00:00 2026-05-30T07:09:33+00:00

This might be quite simple but I have spent hours in Google but couldn’t

  • 0

This might be quite simple but I have spent hours in Google but couldn’t find a relevant answer.

I am trying to put the below logic into hibernate but i am not able to figure out how.
This is my setup: Mysql database with 2 tables T1(ID,C1,C2) and T2(column1,column2,column3).
This is what I want to implement

    results = select ID, from T1 //This will result in multiple rows.

    for(eachRow in results )
    {
    select column1,column2,column3 from T2 where ID=eachRow.ID
    //Do some computation like
    //Assign value of table "T1" column "C1" to table "T2" column "column1"
    column1 = eachRow.C1

    }

For now I could think of a logic of reading the entire table using the Hibernate “from” clause into a List and iterating through it. However this might cause a OutOfMemory exception. Could you please suggest how the HQL must be?

This is what I did

Session session = HibernateSession.getSessionFactory().openSession();
        Transaction aTableTx = null;
        try {
            aTableTx = session.beginTransaction();

            _allRows = session.createQuery("from T1").list();

            for (Iterator<T1> iterator = _allRows.iterator(); iterator.hasNext();)
            {
                T1 aRow = iterator.next();
                //Here I am planning to run a similar to
                            //_allRows = session.createQuery("from T2").list();
                            //Store the result and iterate through the list, but 
                            //it is very inefficient.
            }

            aTableTx.commit();
  • 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-30T07:09:34+00:00Added an answer on May 30, 2026 at 7:09 am

    You can scroll to the results of a query, using the scroll() (or iterate()) method, rather than the list() method.

    Make sure to regularly flush and clear the session, as explained in the hibernate documentation of batch updates.

    Also, the inner query should at least have a where clause, as your pseudo-SQL query has one. The two entities should probably be associated with OneToMany or OneToOne column, which would avoid the need for this inner query completely.

    I think the best thing to do would be to read the Hibernate documentation.

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

Sidebar

Related Questions

This might be a simple question but I've searched and searched and can't find
This might look like a beaten question, but could not find an answer at
Unfortunately, the answer to this question isn't quite as simple as it sounds... but
This might seem like a simple question. But I have been looking for an
I know this might seem like a simple question, but its answer has been
This might be a simple question for some people since it was quite hard
I know this question might sound quite silly, but I somehow found myself stuck
I wondered if someone might have some insight into this. jqGrid is quite happy
This might sound like a stupid question but just trying to learn something here.
This might have to be broken down a bit but what i want to

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.