-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate performance question
PostPosted: Fri Aug 22, 2008 5:46 am 
Newbie

Joined: Fri Aug 15, 2008 3:33 am
Posts: 17
Hi,

I am new to hibernate and right now I have some performance problems.
I want to change an already small web application which previosly used only properties and it didn't have any relation between tables. I tried to change this to one-to-many relation.
Previosly the application worked, but the interogations were made in the hard way. For example: I have a table customer and another table house. A customer can have many houses. For this reason a foreign key to customer was introduced by me in house.

Previosly to know the houses for one cusotmer the interogation was made through the HouseDao Object everytime. Now I have a field of type list in my Customer POJO and I want to get directly all the house through this list. I set to lazy-loading in the hibernate mapping file.

But after 2 or 3 interogation the application crash with this message:
"11:28:22,385 INFO [STDOUT] 11:28:22,370 WARN [OgnlValueStack] Caught an exception while evaluating expression 'accommodationUnits' against value stack
Caught an Ognl exception while getting property accommodationUnits - Class: ognl.OgnlRuntime
File: OgnlRuntime.java
Method: getMethodValue
Line: 935 - ognl/OgnlRuntime.java:935:-1
at com.opensymphony.xwork2.util.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:106)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)
at ognl.ASTProperty.getValueBody(ASTProperty.java:92)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at ognl.SimpleNode.getValue(SimpleNode.java:210)
at ognl.Ognl.getValue(Ognl.java:333)
at ognl.Ognl.getValue(Ognl.java:310)
at com.opensymphony.xwork2.util.OgnlUtil.getValue(OgnlUtil.java:190)
at com.opensymphony.xwork2.util.OgnlValueStack.findValue(OgnlValueStack.java:208)"


And I don't know in which direction I should go. Should I stick with the old method (all table fields are mapped als properties in the hibernate mapping file) or I should try to accomplish the associations also in the hibernate mapping file?

Any advice will be very appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 9:48 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Unfortunately, this exception trace is not quite clear. In fact, this might even be no problem with the Hibernate mapping at all. Try debugging the "getAccommodationUnits" method wherever it is to check the state of your persistent objects at that time. Also, make sure the session is open to make sure lazy loading works.

It would help to see the actual mappings and some of the DAO code in order to better help you.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 8:53 am 
Newbie

Joined: Fri Aug 15, 2008 3:33 am
Posts: 17
Hi,

Sorry for my late answer.

Yes I try to implement the lazy loading in an application which use Struts2, Spring and Hibernate. But when the lazy property should be initialized the connection is closed.

I spent some time and I hound that I should implement a well-known pattern in the hibernate world but I don't know exactly how.
Some information are on this link:
http://www.hibernate.org/43.html

If someone knows a tutorial or an example, please let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2008 5:14 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Indeed very common problem. You will have to go through a small checklist on your current code:

- do not open or close session in DAOs
- do not start or end transactions in DAOs or services
- use some ThreadLocal strategy to get the session (there is a small HibernateUtil class around the internet, or you can configure the session to be RESOURCE_LOCAL (JPA)

This will get you going to implement the filter that the documentation page you cited explains. This filter is intended to keep the session open until after the page is rendered, therefore providing lazy loading for as long as it can be used.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.