[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6280) JPA criteria API don't bind numeric field

William Ashley (JIRA) noreply at atlassian.com
Mon Jul 25 17:31:15 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6280?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43058#comment-43058 ] 

William Ashley commented on HHH-6280:
-------------------------------------

Since the other ticket is closed I'll use this one.

There's another side effect of this behavior which nobody has pointed out: it bypasses any UserType that might be in place for the property. So in a way, all LiteralExpressions against numeric UserType'ed properties are broken. I ran into this today for a property of type long that maps, via a UserType, to BINARY in the database. The workaround is to use a ParameterExpression, but this is pretty messy and hopefully a future version of hibernate will address it.



> JPA criteria API don't bind numeric field
> -----------------------------------------
>
>                 Key: HHH-6280
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6280
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: entity-manager
>    Affects Versions: 3.5.0.Beta-1, 3.5.0-Beta-2, 3.5.0-Beta-3, 3.5.0-Beta-4, 3.5.0-CR-1, 3.5.0-CR-2, 3.5.0-Final, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.6.0.Beta1, 3.6.0.Beta2, 3.5.5, 3.6.0.Beta3, 3.6.0.Beta4, 3.5.6, 3.6.0.CR1, 3.6.0.CR2, 3.6.0, 3.6.1, 3.6.2, 3.6.3, 3.6.4
>            Reporter: gwa
>
> 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:
> {code:java}
> @Entity
> public class User {
> 	@Id
> 	private int id;
> 	private int age;
>         ...
> }
> {code}
> {code:java}
>     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();
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list