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

Steve Ebersole (JIRA) noreply at atlassian.com
Tue Aug 30 16:32:02 EDT 2011


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

Steve Ebersole commented on HHH-6280:
-------------------------------------

I almost always use the {{Type}} interface directly when implementing custom types.  So trying to distinguish based on {{instanceof UserType}} is not a good approach.  Good thought, I just know its not going to work.

So iirc the issue that lead me to use literals here had to do with scale and operations.  Meaning (again, iirc) some databases needed to know type information to be able to properly handle something like {{... ? + ? ...}}, etc.  So the choice was to either wrap all such params in {{CAST}} function calls and hope/pray the db implemented a proper {{CAST}} function or use literals.  In the end I opted for the literal route because, well, thats what the user asked for up front.  Wrapping in function calls will limit the databases ability to leverage indexes in quite a few databases.

Gonna move this to the next release so we can discuss this some more.

> 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.5, 3.6.4
>            Reporter: gwa
>            Assignee: Steve Ebersole
>              Labels: jpa2
>             Fix For: 4.0.0.next
>
>
> 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