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.
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...
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Joined: Aug 17, 2012
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.