• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tuning Hibernate Collection Loading  RSS feed

Jason Ferguson
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help.

I have a class, Region. Region has a Collection of Organizations belonging to it (i.e. an Organization exists in the Northeast, etc). It's defined as a bi-directional One-To-Many/Many-to-One:


@OneToMany(targetEntity = Organization.class, mappedBy = "region", fetch = FetchType.LAZY)
@NotFound(action = NotFoundAction.IGNORE)
public Collection<Organization> getOrganizations() {
return organizations;


@ManyToOne(targetEntity = Region.class, fetch = FetchType.LAZY)
@JoinColumn(name = "REGION_ID")
public Region getRegion() {
return region;

The Organization also has a child Collection of subordinate organizations, meaning that even though there may only be 8 Regions, Organizations are slow to initialize due to the recursive nature of the initialization. UNFORTUNATELY, since a region is geographic, an Organization's parent organization may not be in the same region as itself or its siblings. So, Region's Collection of Organizations does a ton of extra work initializing the organizations (because they initialize children, etc). But every organization is in the collection as a separate member, even if its parent is too. Still with me?

Unfortunately, I need the Organization's id field (an int) and name (a String), which triggers the initialization. (you should see how insane the console goes with Show SQL turned on).

Does anyone have any ideas for tuning this particular issue?


It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!