Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Too slow Application with JPA

 
Yesid Saval
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!
 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Yesid Saval
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic