Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clazz_ attribute in hibernate query

In Hibernate table per concrete class strategy when fetched with super class following query is generated:

SELECT vehicle0_.VEHICLE_ID    AS VEHICLE_ID1_2_,
  vehicle0_.MANUFACTURER       AS MANUFACTURER2_2_,
  vehicle0_.PASSENGER_CAPACITY AS PASSENGER_CAPACITY1_0_,
  vehicle0_.LOAD_CAPACITY      AS LOAD_CAPACITY1_1_,
  vehicle0_.clazz_             AS clazz_
FROM
  (SELECT VEHICLE_ID,
    MANUFACTURER,
    PASSENGER_CAPACITY,
    NULL AS LOAD_CAPACITY,
    1    AS clazz_
  FROM PassengerVehicle
  UNION ALL
  SELECT VEHICLE_ID,
    MANUFACTURER,
    NULL AS PASSENGER_CAPACITY,
    LOAD_CAPACITY,
    2 AS clazz_
  FROM TransportationVehicle
  ) vehicle0_

vehicle0_.clazz_ is selected in query which is not there in table nor in class, what is this clazz_ attribute?

like image 367
eatSleepCode Avatar asked Jun 21 '26 14:06

eatSleepCode


1 Answers

That's inheritance discriminator.

When you joined your subclass with super class, do avoid the confusion while instantiating from the result set, hibernate internally uses the column 'clazz'.

like image 59
Suresh Atta Avatar answered Jun 24 '26 04:06

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!