mercredi 26 septembre 2018

Is Hibernate Criteria API Deprecated and if so what API should we use?

Yes:

https://stackoverflow.com/questions/31200850/is-hibernate-criteria-api-deprecated-and-if-so-what-api-should-we-use
AFAIK and off looking at the Javadocs, the Hibernate Criteria API is not deprecated. However, there is a very good argument for using JPA over hibernate, as it means you can switch between persistence providers without having to modify your code. Where as if you go with the Hibernate Criteria API, then your code is completely tied in to Hibernate.

Update 06/07/16

"This appendix covers the legacy Hibernate org.hibernate.Criteria API, which should be considered deprecated.
New development should focus on the JPA javax.persistence.criteria.CriteriaQuery API. Eventually, Hibernate-specific criteria features will be ported as extensions to the JPA javax.persistence.criteria.CriteriaQuery. For details on the JPA APIs, see Criteria.".
This means, the Hibernate criteria is usable as it isn't officially @Deprecated, but you should be using JPA instead!

Exemple :

CriteriaBuilder builder = entityManager.getCriteriaBuilder();

CriteriaQuery<Person> criteria = builder.createQuery( Person.class );
Root<Person> root = criteria.from( Person.class );
criteria.select( root );
//Type Safe, on doit active le processeur d'annotation 
// 

How to use Hibernate JPA 2 Metamodel Generator?

https://stackoverflow.com/questions/44737254/how-to-use-hibernate-jpa-2-metamodel-generator criteria
.where( builder.equal( root.get( Person_.name ), "John Doe" ) ); List<Person> persons = entityManager.createQuery( criteria ).getResultList();

Activation dans IntelliJ:


Aucun commentaire:

Enregistrer un commentaire

to criticize, to improve