Is legacy Criteria API still recommended?

只愿长相守 提交于 2019-12-23 17:39:19

问题


My team has been using hibernate Criteria API for a long time under Hibernate 3.x. Recently, we want to upgrade Hibernate version to 5, but the Criteria API seemed not be recommended any more. But JPA looks like a totally different API which we don't want to risk. Should we keep using the old Criteria?


回答1:


Well, the warning in the Version 5.0 Criteria Chapter is pretty darn big:

Hibernate offers an older, legacy org.hibernate.Criteria API which should be considered deprecated. No feature development will target those APIs. Eventually, Hibernate-specific criteria features will be ported as extensions to the JPA javax.persistence.criteria.CriteriaQuery. For details on the org.hibernate.Criteria API, see Legacy Hibernate Criteria Queries.

And there's more:

Users of the older Hibernate org.hibernate.Criteria query API will recognize the general approach, though we believe the JPA API to be superior as it represents a clean look at the lessons learned from that API.

So, it seems like it's really up to your team. It took me a while to get used to the JPA API, but it's pretty smooth sailing now. I have dropped back into Hibernate for performance for very large fetches, but in general I'm not having any problem using anything JPA. I tend to use @NamedQueries for basic acccess, and the Criteria API if I need something more dynamic.

EDIT: Update I was able to resolve the performance issue and the application is strictly JPA now.




回答2:


If you are unable to move your code from the legacy Hibernate Criteria API to JPA API for reasons of time constraints/project deadlines/other risks, you should at the very least set some sort of a timeline to get back to it. Hibernate will most likely drop the deprecated Criteria API completely within the next 2 major versions.



来源:https://stackoverflow.com/questions/36943426/is-legacy-criteria-api-still-recommended

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!