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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:06:47+00:00 2026-05-26T21:06:47+00:00

Guys, please help me with the following problem. I have encountered the famous cannot

  • 0

Guys, please help me with the following problem.

I have encountered the famous “cannot simultaneously fetch multiple bags” error because I have two Lists in my Parent Entity. Here is a scratch of code:

class Manager{
    @OneToMany(cascade = CascadeType.ALL)
    @Fetch(FetchMode.JOIN)
    @IndexColumn(name = "id")
    private List<Action> actions;

    @OneToMany(cascade = CascadeType.ALL)
    @Fetch(FetchMode.JOIN)
    @IndexColumn(name = "id")
    private List<Activity> activities;
(...)
}

The mapping is unidirectional.

OK, I have googled that I can use IndexColumn annotation to fix it. I have implemented that, as you see, and now I dont get the mentioned exception. But the problem is that now if I want to get all Managers from db I receive MORE manager instances that really exist!

For example 9 Manager instances if I have only 1 manager and 3 child instances in each collection. I can understand why this happens: Hibernate produces a select which looks like

select ... from Manager this_ 
left outer join manager_action actions3_ on this_.id=actions3_.Manager_id 
left outer join Action action4_ on actions3_.actions_id=action4_.id 
left outer join Manager_Activity activities5_ on this_.id=activities5_.Manager_id 
left outer join Activity activity6_ on activities5_.activities_id=activity6_.id 

… and it really fetches MORE rows than one.

Why this happens?
How can I fix it?

  • 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-26T21:06:48+00:00Added an answer on May 26, 2026 at 9:06 pm

    Hibernate makes a cartesian product and doesn’t dedeuplicate in this case. Cartesian products like this (3 actions * 3 activities = 9 rows) only work well with Sets instead of Lists.

    Even with two Sets, you should maybe avoid these kinds of cartesian products. Think about it: retrieving just one manager with 100 actions and 100 activities retrieves 10,000 rows from the database. You should perhaps make two queries:

    • one which fetches the manager with its actions (100 rows)
    • one which fetches the same manager with its activities (100 rows)

    That would make only 200 rows instead of 10,000. And the result will be the same because the activities will be attached to the same Manager instance in the session. It will also avoid the duplication problem you’re having.

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

Sidebar

Related Questions

Hi Guys can you please help me with this error? What is it? Server
Guys Please help me to solve this floating problem.I tried different methods but anything
Hi Guys could you please help me refactor this so that it is sensibly
I wonder if you guys could help me. I have a table called modules
Can you guys please help me with this jsFiddle?: http://jsfiddle.net/4CNKa/2/ I am trying to
Hy guys, can anybody please help me with a subquery in Oracle database 10g?
I'm pulling my hair out because I've run into the following problem with one
I have the following problem. Table labels include the record labels. Table albums include
My problem is related to Android. I have the following code (non-relevant parts omitted):
Hey Guys I would very much appreciate some help with the following. We're using

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.