Hi everyone.
I'm in the final stage of developing web-based CMS application, and came across performance issues. I wonder if I went the wrong way.
Application uses Struts + Hibernate + AS400. It is multitiered in terms of that it has stricltly separated layers (BO(businecc objects), DA(data access), TM(transaction management in terms of "application transactions") etc..)
I have a service among others that uses ThreadLocal to hold the current Session instance, just like described in the Hibernate reference.
Having that application separated in layers I have chosen to use the second approach for using Session instances described in the reference:
Everitime I need to read/insert/update/delete something I obtain the session object from my service, perform some actions and call session.close().
This way, it is impossible (I think) to have lazy initialization for parent entities in the app. I've desided not to load all the graph (because this is not necessary and impact performance a lot) but instead to read what I need right from the db, for instance:
If I have some entity that must be presented on the web page, but it has lots of resources and I only need some of them on the page. I have implemented the following method:
EntityResource getMediaResource(Entity parent, String resourceName) {
////obtain Session instance from the service
Query q = session.createQuery("from EntityResource er where er.parent.id=? and er.name=?");
q.setLong(0, parent.getId().longValue);
q.setString(1, resourceName);
List result = q.list();
if (result.size()>0)
entityResource = (EntityResource)result.get(0);
//// skipped exception handling
So this is basically the idea. On the page there might be 5-10 entities with 2-4 types of resources each and I call the above (and alike for other types of resources) method for every entity to form a web page.
I skipped also that each entity can have different resources of the same type and name (this is multi language support - this application going to support 10-20 domains (such as
www.test.com,
www.test.us,
www.test/ru etc.. and give localized content for each requested url))
the other approach was to call something like:
parentEntity.getEntityResources() and iterate them until I get the needed resource (of needed type, name and localization). But as I mentioned earlier, I have 5-10 entities on the page with 2-4 types of resources each.
So my question is did I do right or wrong going the first approach?
How heavy performance impact has session.close() and then using it again? Does the new read opens new JDBC connection?
Thanks in advance.