What are some of the real world example where JPA2 Criteria API is more preferable?

后端 未结 4 1318
不思量自难忘°
不思量自难忘° 2020-12-13 10:15

I have taken a look at JPA 2.0 Criteria API, but I found it to be too cumbersome unlike Hibernate Criteria. Is there any good reason to use JPA 2.0 Criteria API rather than

4条回答
  •  渐次进展
    2020-12-13 10:42

    For me the real world example where JPA2 shines is in when you need to create a query based on input from a user. I am not talking about a very simple where with one parameter. I mean when you have made an advanced search option in your application. One that requires joins when a certain parameter is filled. You don't what to concatenate your HQL or SQL to include a large set of parameters, extra joins and functions. Custom SQL requires a lot of tests to prove it works. Adding extra search options to HQL and SQL requires a lot of rework whereas this might be simpler in JPA.

提交回复
热议问题