Right now I am using JPA. What I would like to know is the following:
I have a lot of tables mapped to each other. When I look at the log, I see that a lot of information is being pulled out from the database after a simple query. What will happen if there will be a lot of queries at a time? Or will it work fine? How can I increase performance?
There is an overhead that ORM framework comes with. Because it’s fairly high level, it sometimes needs to generate a lot of native SQL queries to get you what you want in one or two lines of JPQL or pure
EntityManageroperations.However, JPA uses two caches – L1 and L2. One operates on the entities level, other on PersistenceUnits level. Therefore, you might see a lot of SQL queries generated, but after some time, you should have some of the data cached.
If you’re unhappy with the performance, you could try using lazy loaded collections or fetching the required data by yourself (you might be interested in Bozho’s post regarding this matter).
Finally, if you see that the cache hasn’t improved your performance and that the hand-made JPQL queries are not doing the job right – you can always revert to plain SQL queries. Beware, that those queries bypass the JPA caches and might require you to do some flushes before you execute the native query (or invoke it at the beginning of the active transaction).
Despite the optimisation route you’ll choose – firstly test it in your environment and answer yourself if you need this optimisation at all. Do some heavy testing, performance tests and so on.
“Premature optimization is the root of all evil.” D. Knuth