aspose file tools*
The moose likes Object Relational Mapping and the fly likes Too slow Application with JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Too slow Application with JPA" Watch "Too slow Application with JPA" New topic
Author

Too slow Application with JPA

Yesid Saval
Greenhorn

Joined: Aug 17, 2012
Posts: 2
Hello everybody, my problem is the following:

I have a problem with an application which is being maintenance and it made with JPA. The application has a lot of tables and many relationships.
Reviewing the relationships, they are bidirectional each other and they load eagerly, also, I reviewed the SQL statements when I get an single object and
of course I get all information about this object with the data of its relationships.

What can I do so that the application is faster?

The application is on an environment JEE and it uses only stateless EJB.

I tried replace relationships with lazy attribute, at the beginning when I did a query, it took 5 seconds (before it took 1 minute aprox.),
seemed that all was well, but when I wanted to merge the same object of the query, I got the LazyInitilization error,
of course because the EJB component is a stateful and the object is detached.

Please help me to solve this issue

Thanks a lot
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Take a look at this blog for suggestions
http://www.javacodegeeks.com/2011/10/avoid-lazy-jpa-collections.html

Make sure you are back inside your persistence layer within a transaction when you do your merge.


[How To Ask Questions][Read before you PM me]
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Welcome to Java Ranch!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8396
    
  23

Yesid Saval wrote:What can I do so that the application is faster?

I fear that merely replacing 'eager' with 'lazy' is treating the symptoms rather than the problem.

Does your database only service a JPA layer, or are there other components of the system written in, say, PL/SQL? If so, you may want to look at how they're written, or consult with someone like a business analyst or DBA (or indeed a JPA expert) to make sure that your code really is mirroring the database structure properly.

The other possibility of course is that the database itself is in need of review...

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Yesid Saval
Greenhorn

Joined: Aug 17, 2012
Posts: 2
Hello Bill, Winston and everybody

Thanks for responding so fast. I'm sorry for not answering before, I've been a little busy. We was checking the possible solutions you proposed and we reached two conclusions: First, We are showing the fields necessary of the entities on reports (new queries) and the performance improved enough. (Before each query took about 2 mins., now it take about 3 sec.), and seconds, when an object is going to save or update and it has other relations with other entities, we only associate the id field of the foreign key of the corresponding entity and not the whole object. The response time got better when we save an entity with its relations, however it has to develop more, but the performance is better now.

Again Thanks a lot for your help!!!

Bye...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Too slow Application with JPA