Uploaded image for project: 'Hibernate ORM'
  1. HHH-6280

JPA criteria API don't bind numeric field

    Details

    • Suitable for new contributors:
      Yes, likely
    • Last commented by a user?:
      true

      Description

      When you use JPA criteria API, the numeric value are not binded but are directly set in the SQL instead.

      eq: you have a generated SQL like:
      select ... from ... where age=12;
      instead of
      select ... from ... where age=?;
      With '12' as parameter.

      when you test the following code:

      @Entity
      public class User {
      	@Id
      	private int id;
      
      	private int age;
              ...
      }
      
          CriteriaBuilder builder=em.getCriteriaBuilder();
          CriteriaQuery<User> query=builder.createQuery(User.class);
          Root<User> root=query.from(User.class);
          query.select(root).where(builder.equal(root.get("age"),12));
          em.createQuery(query).getResultList();
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated: