Reputation: 1177
Is there any performance related features between createNamedNativeQuery and createNativeQuery, because we are planning to use named query for HQL query's and maintain separate query file for native SQL query.
Upvotes: 2
Views: 3719
Reputation: 11602
Named Native Query : The scope of this query is persistence context & can be used in the application by specifying its identifier. The query can't be changed afterwards, its static. They are validated only once, at the server startup(JBoss specific)
Native Query : A plain native sql query. Can build dynamic query at runtime & execute it. They will be validated each time the query is executed.
In small applications with normal database operations, difference might not be notable, but in enterprise applications with numerous database calls, will have an effect.
Performance of named native queries is better than that of native queries.
Upvotes: 6