segunda-feira, 10 de janeiro de 2011

JPA 2.0 Criteria Sucks

2

I sometimes need to use the Criteria in JPA, I don't know why, but the create query method not accept order with asc and desc in the same query, the Criteria support it, but damn, it's very hard, I don't know who think this code

ParameterExpression age = qb.parameter(Integer.class);
Predicate condition = qb.gt(p.get(Person_.age), age);
c.where(condition);
TypedQuery q = em.createQuery(c); 
List result = q.setParameter(age, 20).getResultList();

is better than this one

String jpql = "select p from Person p where p.age > :age";
Query query = em.createQuery(jpql).setParameter("age", 20);
List result = query.getResultList();

I don't need to map my class into another object called metamodel, one change in a model results into two changes, the model and the metamodel. Go to hell with de metamodel, we don't want, and don't need it, I write my queries using JPQL and don't want to use the Criteria API. Why they don't use the hibernate style? The code below isn't better?

List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.like("name", "Fritz%") )
    .add( Restrictions.between("weight", minWeight, maxWeight) )
    .list();

Yes, I copy this codes from IBM and Hibernate:).

2 comentários:

Unknown disse...

True.. ainda prefiro Hibernate puro.

Anônimo disse...

Tentaram copiar o .net e fizeram essa porcaria. Fizeram só 50%, os outros 50% seria estender o Java para compilar outras linguagens embutidas (ou seja, o próprio JPQL). Ai sim faz sentido ter esta estrutura, que na verdade seria "escondida"...
This smells like CMP/EJB 2 :P

 
Design by ThemeShift | Bloggerized by Lasantha - Free Blogger Templates | Best Web Hosting