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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:16:16+00:00 2026-05-20T01:16:16+00:00

I have an application that uses hibernate. At one part I am trying to

  • 0

I have an application that uses hibernate. At one part I am trying to retrieve documents. Each document has an account number. The model looks something like this:

    private Long _id;
private String _acct;  
private String _message;  
private String _document;    
private String _doctype;  
private Date _review_date;  

I then retrieve the documents with a document service. A portion of the code is here:

public List<Doc_table> getDocuments(int hours_, int dummyFlag_,List<String> accts) {
        List<Doc_table> documents = new ArrayList<Doc_table>();
    Session session = null;
    Criteria criteria = null;
    try {
        // Lets create a previous Date by subtracting the number of
        // subtractHours_ passed.
        session = HibernateUtil.getSession();
        session.beginTransaction();
        if (accts == null) {
            Calendar cutoffTime = Calendar.getInstance();
            cutoffTime.add(Calendar.HOUR_OF_DAY, hours_);
            criteria = session.createCriteria(Doc_table.class).add(
                    Restrictions.gt("dbcreate_date",  cutoffTime.getTime()))
                    .add(Restrictions.eq("dummyflag", dummyFlag_));
        } else 
        {   criteria = session.createCriteria(Doc_table.class).add(Restrictions.in("acct", accts));
        }
        documents = criteria.list();
        for (int x = 0; x < documents.size(); x++) {
            Doc_table document = documents.get(x);
               ......... more stuff here
                    }

This works great if I’m retrieving a small number of documents. But when the document size is large I get a heap space error, probably because the documents take up a lot of space and when you retrieve several thousand of them, bad things happen.

All I really want to do is retrieve each document that fits my criteria, grab the account number and return a list of account numbers (a far smaller object than a list of objects). If this were jdbc, I would know exactly what to do.

But in this case I’m stumped. I guess I’m looking for a way where I can bring just get the account numbers of the Doc_table object back.

Or alternatively, some way where I can retrieve documents one at a time from the database using hibernate that fit my criteria (instead of bringing back the whole List of objects which uses too much memory).

  • 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-20T01:16:17+00:00Added an answer on May 20, 2026 at 1:16 am

    There are several ways to deal with the problem:

    • loading the docs in batches of an smaller size
    • (The way you noticed) not to query for the Document, but only for the account numbers:

      List accts = session.createQuery(“SELECT d._acct FROM Doc d WHERE …”);

    or

     List<String> accts = session.createCriteria(Doc.class).
                 setProjection(Projections.property("_acct")).
                 list();
    
    • When there is a special field in you Document class that contains the huge amount Document byte data, then you could map this special field as a Lazy loaded field.
    • Create a second entity class (read only) that contains only the fields that you need and map it to the same table
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses Hibernate for its domain objects. One part of
I have a JPA/Spring application that uses Hibernate as the JPA provider. In one
We have a Java web application that uses Spring and Hibernate and has a
I have an application that uses Hibernate. It generated the following SQL statement. I
We have an application that uses Hibernate's 2nd level caching to avoid database hits.
I have a client application that connects to a server. The server uses hibernate
I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I have an application that uses Hibernate to connect to my MySQL database. I'm
I have an application that uses the Ultra Win Grid and has a column
I have an application built on Spring MVC that uses Hibernate for all of

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.