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