3 Replies Latest reply on Oct 7, 2009 12:37 PM by blabno

    How to do typesafe queries with seam


      I'm a Seam/JavaEE beginner and i have a question concerning typesafe queries.
      In the examples, books and tutorials about seam i saw until now, all queries were done with unsafe queries a la

      List existing = em.createQuery(
               "select username from User where username = #{user.username}")

      Is there a possibility to do that typesafe in seam? I saw that typesafe queries are possible with JPA 2.0 which looks like

      EntityManager em = ...
      QueryBuilder qb = em.getQueryBuilder();
      CriteriaQuery<Person> c = qb.createQuery(Person.class);
      Root<Person> p = c.from(Person.class);
      Predicate condition = qb.gt(p.get(Person_.age), 20);
      TypedQuery<Person> q = em.createQuery(c); 
      List<Person> result = q.getResultList();

      This seems far less errorprone to me than the unsafe method...

      Is it possible to use that typesafe query api with seam (or with hibernate, maybe it's more an hibernate issue)? Where can i find useful documentation to do that?
      Or am i completely wrong and one don't even need typesafe queries in seam because of the CRUD framework (as i said i just began and didn't use the crud framework much until now)?