JPA Criteria API Typesafety on equal

Description

By Using the Typesafe JPA Criteria API i dont get a Compile Error by compiling the code below:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("hibernatetest");
EntityManager em = emf.createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Employee> c = cb.createQuery(Employee.class);
Root<Employee> root = c.from(Employee.class)

// No Compile Error, but Exception on Runtime, because "name" is a String and the check parameter is an Integer
Predicate condition = cb.equal(root.get(Employee_.name), 1);

Obviously thats because the method in CriteriaBuilderImpl takes an Object as the second argument:

public Predicate equal(Expression<?> x, Object y) {...}

If this method would look like this the code above will show the correct Compile error

public <T> Predicate equal(Expression<T> x, T y) {...}

Corresponding Example Project is attached.

Environment

Java 1.6.0_18
Hibernate 3.5.1-Final

Assignee

Unassigned

Reporter

Sebastian Braun

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Affects versions

Priority

Major
Configure