3

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?

eatSleepCode
  • 4,427
  • 7
  • 44
  • 93

1 Answers1

2

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'.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • I thought inheritance discriminator is needed when working with single table strategy, this column is added while working with joined and table_per_class strategy. In both of the strategy it does select from separate table then why this column is needed? – eatSleepCode Sep 11 '15 at 07:04
  • There are two more questions that are really putting me in confusion. It would be nice and helpful for me if you can answer those question. http://stackoverflow.com/questions/32516409/difference-hibernate-with-dialect-and-without-dialect and http://stackoverflow.com/questions/32472739/hibernate-merge-method-persists-the-copy-of-entity – eatSleepCode Sep 11 '15 at 07:07
  • @eatSleepCode It selects that is fine, but which subclass needs to instantiate with hibernate ? That's the information /need – Suresh Atta Sep 11 '15 at 07:11
  • Thanks allot for the answer. – eatSleepCode Sep 11 '15 at 07:12
  • So we need to add Discriminator for this table @eatSleepCode ? – Saige Zhang Mar 29 '19 at 04:04