orm - Hibernate -- Criteria vs named query -
i'm trying compare hibernate criteria named queries performance. i'm aware depends on actual query , last word on how profile in runtime. still, trying sort out goes each.
i tried organize q in 2 parts & looking verification/correction on both:
part-1 -- how hibernate criteria , named queries work basically:
criteria works on parameters. in runtime, query doesn`t need parsing-- has several search , "present-in-form" params order results, return them scrollable etc. haven't read/verified this, criteria works indexes on fields (based on parameters set on them) make faster.
so, advantage of criteria compared plain hql speed during execution.
named queries have same advantage on hql-- query parsed once @ start-up. executed wherever necessary in application.
part-2 -- comparing two:
so in picture,
how criteria , named-queries compare 1 another?
criteria works complicated queries across multiple tables , multiple params-- has means optimize , make query fast(?)
named-queries have advantage of "define-once-use-everywhere" , quite alright "light" queries-- less complicated searches small amount of params typically on single table. better on frequent queries.
note: seen useful hibernate criteria vs hql: faster? among other discussions.
tia.
you don't choose 1 on other based on performance. in end, becomes sql query anyway, , matters performance of sql query.
executing sql query orders of magnitudes slower parsing hql query , transforming sql. if don't use named query, performance won't worse.
you choose criteria on hql based on capabilities , readability.
if want readable, use hql query.
if want compose query dynamically, based on various, optional, search criteria, criteria api allows that, , more convenient dynamically composing hql query.
Comments
Post a Comment