I have an unusual problem that I can't seem to figure out how to deal with. Basically I have a many to many mapping from categories to news articles (ie, one news article can be listed under many categories, and a category can have many news articles).
Now everything functions just fine, until I try and add a news article to a category that contains 90k+ news articles. Hibernate decides to fetch all 90k news articles when I call category.getDocuments().add(d) which is a huge resource hog and I run into a problem of running out of memory. While I would prefer to use a set mapping, I've tried many different mappings and after reading through the documentation a bunch and have settled on using an idbag with a hilo id generator for the collection id column. I would think that since the idbag has no duplicate matching and with the lazy=true/extra option set, it wouldn't need to preload the document list.
Am I missing something? Would inverse mappings help? Or would I run into the same problem with loading when I called category.getDocuments().add(d). Is there a way to trick hibernate into using SQL queries to figure out collisions with sets? or stop hibernate from loading idbags for adding?
Any help would be appreciated.
|