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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:03:24+00:00 2026-06-04T21:03:24+00:00

I am trying to create an Entity that has a Parent and children from

  • 0

I am trying to create an Entity that has a Parent and children from the same type as he is (like a tree).

here is the code:

@Entity
@Table(name = “areas”)
public class Area {

@Id
@Column(name = "id")
@GeneratedValue
private int id;

@Column(name = "name")
private String name;

@Column(name = "area_type", nullable = true)
private int areaType;

@ManyToOne
@JoinColumn(name="parent_area_id")
private Area parentArea;

@OneToMany (fetch = FetchType.EAGER, mappedBy = "parentArea")
@Cascade({CascadeType.ALL})
private Collection<Area> childAreas = new ArrayList<Area>();

i have seen this code in a few posts in stack overflow
first of all when i try to save such entity to the database i get:

nested exception is org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags

furthermore, there is something i don’t understand fully about this design.

if the children areas are mapped by the parent areas. wont it mean that “this” area will be among the children fached?
i other words… wont the children areas be the children of the parent area of “this” class.

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-04T21:03:25+00:00Added an answer on June 4, 2026 at 9:03 pm

    This seems like a similar problem. You should try:

    @LazyCollection(LazyCollectionOption.FALSE)
    @OneToMany (mappedBy = "parentArea")
    @Cascade({CascadeType.ALL})
    private Collection<Area> childAreas = new ArrayList<Area>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an entity in my model that has two properties for
I am trying to create an Entity that has a byte[12] id in hibernate.
I am trying to create an application that has two UITableViews placed side-by-side. The
I'm trying to use Dynamic Data with a entity model that has Abstract class
I am trying to create a program that loads in over 100 tables from
I am trying to create nested routes for a project that has many boards.
I'm trying to create ASP.NET MVC Application with Entity Framework, which has One to
I'm using Entity Framework Code First. The class i'm trying to create contains two
I am having a trouble while trying to create an entity with a custom
I'm trying to use a view to create an ADO.NET entity using a view.

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.