-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Java Hibernate createCriteria generates wrong SQL incorrect
PostPosted: Mon Jun 30, 2014 6:17 pm 
Newbie

Joined: Sun Nov 13, 2011 4:35 pm
Posts: 6
i have a simple Criterion and conjunctions like this.

Code:
   protected Conjunction simpleFilterings(){return (org.hibernate.criterion.Conjunction)Restrictions.conjunction().add(Restrictions.equals("isDeleted","N")).add(Restrictions.isNotNull("studentSchool").add(Restrictions.isNotNull("studentHome");}
    protected Criterion filterOnlyNotDeleted(){return equals("isDeleted","N");}
    protected Conjunction homeFilterings(){return (org.hibernate.criterion.Conjunction)Restrictions.conjunction().add(Restrictions.eq("currentCode",1)).add(Restrictions.eq("currentStatus",1)).add(Restrictions.eq("isDeleted","N"));}

this filters are constant they do not change at any moment.

later i apply on a simple Criteria like this.

Code:
    final Criteria like = session.createCriteria(Student.class).add(simpleFilterings());
    final Criteria schoolCriteria = like.createCriteria("studentSchool","school",JoinType.INNER_JOIN,filterOnlyNotDeleted());
    final Criteria homeCriteria = like.createCriteria("studentHome","home",JoinType.INNER_JOIN,homeFilterings());       

Student have many to One relationship to School and Home means that a student can have one School and one home..

there is strange behavior in the generated SQL because is `homeFilterings` i have a Conjunction with some types of the fields like `isDelete='N' and currentCode=1 and currentStatus=1` as is show above, but when i add this conjunction in the criteria namely

Code:
like.createCriteria("studentHome","home",JoinType.INNER_JOIN,homeFilterings());       


this is generating the wrong data binding i can see it through `P6SpyDriver` the corrent would be

isDeleted='N' and currentCode=1 and currentStatus=1

and is generating something like

isDeleted=1 and currentCode=1 and currentStatus='N'

`of course this is wrong`

in Hibernate is returning 0 results when i know there is results i copy the generated SQL into console and is returning

Truncated incorrect DOUBLE value: 'N'

if i delete the `schoolCriteria` it works or if i use

Code:
like.createCriteria("studentHome","home",JoinType.INNER_JOIN).add(homeFilterings());       


generated the right SQL what i am doing wrong my environment is.

tested on Netbeans,Java 8,Hibernate 4.3.4 and mysql 5.5

the API i am using is this.
![Criteria API][1]

but strangely Hibernate is populating the properties with wrong values.

any help is hugely appreciate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.