• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tuning Hibernate Collection Loading

 
Jason Ferguson
Greenhorn
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:

Region.java:

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

Organization.java:

@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?

Jason




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic