Advantages of Named queries in hibernate?

Named queries are compiled when SessionFactory is instantiated (so, essentially, when your application starts up).

The obvious advantage, therefore, is that all your named queries are validated at that time rather than failing upon execution. The other advantage is that they’re easy(-ier) to maintain – certainly for complex queries.

The disadvantage is that named queries are not customizable at runtime – you can define / supply parameters, of course, but beyond that what you’ve defined is what you’ll get; you can’t even change the sorting. Another disadvantage is that you will not be able to change the named query within a running application server without reloading the SessionFactory.

Leave a Comment