hibernate - Query failing unless I reorder the values in SELECT statement -
i'm trying hql query don't understand why query fails if don't reorder values in select statement
following query not work
query 1
@query("select uf.flight.arrivalairport.iatacode, uf.flight.flightstatus " + "from userflight uf uf.flight.id=?1 , uf.user.id=?2")
generated sql
select airport2_.iata_code col_0_0_, flight1_.flight_status_id col_1_0_, flightstat4_.id id1_6_, flightstat4_.code code2_6_, flightstat4_.description descript3_6_ user_flight userflight0_, flight flight1_, airport airport2_ inner join flight_status flightstat4_ on flight1_.flight_status_id=flightstat4_.id userflight0_.flight_id=flight1_.id , flight1_.arrival_airport_id=airport2_.id , userflight0_.flight_id=? , userflight0_.user_id=?
exception
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown column 'flight1_.flight_status_id' in 'on clause'
if change query following (just reordering select values)
query 2
@query("select uf.flight.flightstatus, uf.flight.arrivalairport.iatacode " + "from userflight uf uf.flight.id=?1 , uf.user.id=?2")
generated sql
select flight1_.flight_status_id col_0_0_, airport4_.iata_code col_1_0_, flightstat2_.id id1_6_, flightstat2_.code code2_6_, flightstat2_.description descript3_6_ user_flight userflight0_, flight flight1_ inner join flight_status flightstat2_ on flight1_.flight_status_id=flightstat2_.id, airport airport4_ userflight0_.flight_id=flight1_.id , flight1_.arrival_airport_id=airport4_.id , userflight0_.flight_id=? , userflight0_.user_id=?
it works , results database.
can tell me why 1 of them working , other not?
note: flightstatus entity , not string value.
the error here:
in first query have:
... airport airport2_ inner join flight_status flightstat4_ on flight1_.flight_status_id=flightstat4_.id ...
so interpreter thinks want link airport2_
, flighstat4_
, on clause isn't correct
instead, in second query, have:
... flight flight1_ inner join flight_status flightstat2_ on flight1_.flight_status_id=flightstat2_.id, ...
the on clause correct 2 tables flight1_
, flighstat2_
edit
when write:
select uf.flight.arrivalairport.iatacode, uf.flight.flightstatus
the interpreter decomposes objects in order:
processes first field:
uf (user_flight) -> flight (flight) -> arrivalairport (airport)
so processes second field:
uf (user_flight) -> flight (flight)
these 2 objects present in tables, reuses them but, order of join defined have first layout (with error).
when change order of field, second field (of first query) has been processed first , old first second, have second lasyout without error.
i hope, i'm clean in explanation :)
Comments
Post a Comment