-->
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: Inconsistent SQL generated by a DetachedCriteria
PostPosted: Fri Jul 13, 2012 6:04 am 
Newbie

Joined: Fri Jul 13, 2012 5:52 am
Posts: 1
Hello community,

I'm facing a problem where an hibernate DetachedCriteria is generating a bogus sqlRequest. I'm pretty sure the criteria is correct though. Any help on the matter would be appreciated.

Here is the criteria code.
Code:
   
DetachedCriteria movementCriteria = DetachedCriteria .forClass(Movement.class);
    movementCriteria.add(Restrictions.isNotNull(Movement.RTD));
    movementCriteria.add(Restrictions.eq(Movement.PARKED, false));
      DetachedCriteria compositionCriteria = movementCriteria.createCriteria(movementCriteria, Movement.CURRENT_COMPOSITION);
      compositionCriteria.add(Restrictions.eq(Composition.TRAIN, trainFilter));
   

    DetachedCriteria wtoCriteria = movementCriteria.createCriteria(movementCriteria, Movement.WAGON_TRANSPORT_ORDER);
    wtoCriteria.add(Restrictions.eq(WagonTransportOrder.STATE, WagonTransportOrder.STATE_STARTED));
    wtoCriteria.add(Restrictions.eq(WagonTransportOrder.LOAD_WEIGHT, 0.d));


Here is the Criteria object in memory :
Code:
DetachableCriteria(CriteriaImpl(fr.model.Movement:this[Subcriteria(currentComposition:), Subcriteria(wagonTransportOrder:)][rtd is not null, parked=false, train=MAS-GEV-120627-61458, state=STARTED, loadWeight=0.0]))


And finaly, this is the SQL result:
Code:
select * from MOVEMENT this_
inner join WAGON_TRANSPORT_ORDER wagontrans2_
                on this_.WAGON_TRANSPORT_ORDER_ID=wagontrans2_.ID
inner join COMPOSITION compositio1_
                on this_.CURRENT_COMPOSITION_ID=compositio1_.ID
where this_.RTD is not null
and this_.PARKED=?
and compositio1_.ID=?                                <- WTF ?
and wagontrans2_.STATE=?
and wagontrans2_.LOAD_WEIGHT=?



As you can see, the generated SQL doesn't match with the criteria. There's a useless and stupid restriction on the composition's ID, and the train's reference isn't restricted. Furthermore, hibernate only binds 3 parameters to the request, producing a "No value specified for parameter 4" error.

Code:
11:48:41,283 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] binding parameter [1] as [BIT] - false
11:48:41,283 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] binding parameter [2] as [VARCHAR] - STARTED
11:48:41,284 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] binding parameter [3] as [DOUBLE] - 0.0


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.