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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:48:35+00:00 2026-06-16T08:48:35+00:00

Ok, I have an entity class with a List member that maps through Hibernate

  • 0

Ok, I have an entity class with a List member that maps through Hibernate to a large list of objects. I do not need to fetch the entire list at query time, I only need the total size of objects that this applies to.

  • List also uses the @Where annotation to only select a
    subset of the elements.
  • List is marked as
    @LazyCollection(LazyCollectionOption.EXTRA) due to its very large size
  • Mapping is done through the use of a link table
  • List has the following sort of mapping:

enter image description here

The @JoinTable of the List uses a join on table 2 and an inverse join on table 3. I am not entirely sure what the SQL generated is because I am not too fluent in SQL.

Anyways, the @Where clause will have some restrictions on it, such as ‘STATUS = ACTIVE’ and possibly some other stuff such as ‘LETTER = ‘A’. Like the example shows, if I do a call like this:

List items = Lists.getItems();
items.size();    // This results in 1 with the restrictions with the @Where clause

The above populates the items with the correct items from Table 3 with the restrictions of the @Where clause.
The first thing I tried without fetching the entire list was this:

int listSize = Lists.getItems().size();     // This results in 3, the @Where clause is not applied

I researched it, and found this issue with Hibernate that I do not believe has been fixed: Hibernate Jira

So, my question is what is the best way to do this? I am not very proficient in SQL or HQL, yet. I am not too familiar with joins and other database terminology, so if any support could be given that would be great.

Thanks!

  • 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-16T08:48:36+00:00Added an answer on June 16, 2026 at 8:48 am

    I ended up doing the following query and setting the parameter:

    public int getActiveCountOfList(long list_id) {
        String sql = "SELECT COUNT(*) FROM TABLE_2 t2 
                     LEFT JOIN TABLE_3 t3 ON t2.ITEM_ID = t3.ITEM_ID 
                     WHERE t2.LIST_ID = :list_id AND t3.LETTER IN ('A', 'B')
                     AND t3.STATUS = 'ACTIVE'";
    
        Object result = session.createSqlQuery(sql).setLong("list_id", list_id)
                           .uniqueResult();
    
        return ((Number) result).intValue();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity similar to the below: public class Entity { public List<DateItem>
In my business model I have Entity class (IPoint interface ) that has a
I have an entity class Foo foo that contains Collection<Bar> bars . I've tried
I have an entity class that has 10 fields. I am using MS Validation
In the project I'm working on now, we have base Entity class that looks
Let's say I have the following entity: public class Store { public List<Product> Products
Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
I have an entity class Document and another one called Space. The relation: @ManyToOne(fetch
I have an Entity object, Item, that looks like this.. public class Item() {
I have a RavenDB mvc applicaton that has a document entity called Member. Each

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.