This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Too slow Application with JPA" Watch "Too slow Application with JPA" New topic

Too slow Application with JPA

Yesid Saval

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

Joined: Mar 07, 2010
Posts: 1648

Take a look at this blog for suggestions

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

Joined: Mar 07, 2010
Posts: 1648

Welcome to Java Ranch!
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 7552

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...


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

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!!!

It is sorta covered in the JavaRanch Style Guide.
subject: Too slow Application with JPA
Similar Threads
Newbie Question: What's the relationship between JPA and EJB?
JPA Native Query
A question for the authors present this week
JPA Where do I need to define the datasource?
Post about: JPA (EJB) Query tips - with source code to download