Hello!
I'm currently experiencing some performance related issues with my Hibernate webapp.
Background:
I have several entities in the database that needs to be translated upon request depending on which "store" the user is in. My currect, really stupid, solution works almost like this:
Code:
class Item {
List<Store> stores; //ManyToMany Mapped relationship to the Store table
private transient String translation;
public String getTranslation() {
return translation;
}
public void setTranslation( translation ) {
this.translation = translation;
}
}
class ItemTranslation {
Store store; //Mapped relationship
Item item; //mapped
private String translation;
}
Then when I load all items from the database, iterate over them and set the translated transient value:
Code:
Store store; //Is kept by the usersession (set depending on which URL the user visits)
List<Item> items = ... //Load using critieria
for( Item itm : items ) {
String translation = ... //Find the translation that matches "itm" and "store"
itm.setTranslation( translation );
}
This of course generated alot of overhead queries and made the site crawl when loading.
Surely there must be some way of getting Hibernate to automatically join Item with ItemTranslation in one query when I load all items? How would I supply my "Store" variable to that automatic query? I suppose I can't just create a special HQL-query to do the job because I load Items (and serveral other, more complex entities) through different Hibernate criterias and therefore need a more "transparent" solution.
Sincerely,
John
Hibernate version:
Hibernate 3.2.3.ga with Annotations
Name and version of the database you are using:
MySQL 5.0