JPA Criteria API Typesafety on equal
------------------------------------
Key: JPA-10
URL:
http://opensource.atlassian.com/projects/hibernate/browse/JPA-10
Project: Java Persistence API
Issue Type: Bug
Affects Versions: 1.0.0
Environment: Java 1.6.0_18
Hibernate 3.5.1-Final
Reporter: Sebastian Braun
Attachments: Example.zip
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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira