We are starting a new projet using JPA/Hibernate. Someone in the team is refusing to use named queries saying that he had performance issues with those before. According to him, the named queries are not only parsed at startup but they also are executed which would slow significantly the startup.

Is it right and if so, is there any configuration to prevent hibernate from executing the queries?

有帮助吗?

解决方案

But they run faster.. So what would you rather have, slower startup or faster query performance.

You also get a nice benefit with validation so you spot your mistakes early..

But this is of course the theory. As always when it comes to performance you should test and verify on your own system!

Here is a nice read on the subject: http://eubauer.de/kingsware/2011/03/25/organize-your-named-jpql-queries/

其他提示

According to him, the named queries are not only parsed at startup but they also are executed which would slow significantly the startup.

No, this is not true. Named queries are not executed at startup. They are being parsed and compiled at startup time, but not executed against a database.

Is it right and if so, is there any configuration to prevent hibernate from executing the queries?

If you are asking about how to prevent compilation of such queries, AFAIK there is no way to disable it.

Although I agree that huge amount of named queries can slow down the application startup, but typically it is not a significant factor.

You have to choose between startup and runtime performance. Personally I usually make some of my JPA queries a named queries (the ones, which runtime performance is essential).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top