Inheritance TABLE_PER_CLASS bad table for column ID to SubClass

Hello,

I have an inheritance of two classes, father and son, and each class can be instantiated and has its own table.
So I am using the TABLE_PER_CLASS inheritance strategy, but by doing this the father’s table @Table (name = TPERE) is considered an included table ??
And the identifier column is considered in the TPERE table instead of TFILS.

An error of definition?
I am also trying through the SINGLE_TABLE strategy, but so far I haven’t found a viable solution.

Thank you for your help.

SuperClass :
2021-10-18 14_33_17-archi-map4j-mapping – ObjetHibernatePereTablePerClass.java archi-jar

SubClass :

Entity :


Table of Entity :

I have the impression that it is the definition of @Table in each level that is causing the problem because it is always looking for the table of the superclass …

Because even by removing the inheritance, suddenly by default SINGLE_TABLE the problem is the same.

How could I define two different tables in two levels?

The base class can not have a table. You will need an empty subclass for which you can define @Table(name = "TPERE")

But even removing @Table on the FATHER class it chooses a table name for the parent class ??

And I also tried by changing the inheritance strategy (by removing @Inheritance) and ditto he wants a table for the father …

I’m lost there …

The problem does not arise if the superclass is defined with @MappedSuperClass.
The problem is that both levels are @Entity.
I’ll see if I can use @SecondaryTable system instead …

SecondaryTable is an error because in the end I only have one table

I understood … from the father he will look for all the girl classes and request them.
I tried by putting @Polymorphisme (EXPLICIT) on the daughter classes but it still searches for the daughter classes.
It does not matter, for the moment I can leave it like that, it works regardless.

Load to father : 

    select
        objethiber0_.ID as id1_14_0_,
        objethiber0_.ACTEURCREATION as acteurcreation2_14_0_,
        objethiber0_.ACTEURMODIFICATION as acteurmodification3_14_0_,
        objethiber0_.ACTEURSUPPRESSION as acteursuppression4_14_0_,
        objethiber0_.DATECREATION as datecreation5_14_0_,
        objethiber0_.DATEMODIFICATION as datemodification6_14_0_,
        objethiber0_.DATESUPPRESSION as datesuppression7_14_0_,
        objethiber0_.ETATOBJET as etatobjet8_14_0_,
        objethiber0_.PERE as pere9_14_0_,
        objethiber0_.FILS as fils1_8_0_,
        objethiber0_.clazz_ as clazz_0_ 
    from
        ( select
            ID,
            ACTEURCREATION,
            ACTEURMODIFICATION,
            ACTEURSUPPRESSION,
            DATECREATION,
            DATEMODIFICATION,
            DATESUPPRESSION,
            ETATOBJET,
            PERE,
            null as FILS,
            0 as clazz_ 
        from
            TPERE 
        union
        all select
            ID,
            ACTEURCREATION,
            ACTEURMODIFICATION,
            ACTEURSUPPRESSION,
            DATECREATION,
            DATEMODIFICATION,
            DATESUPPRESSION,
            ETATOBJET,
            PERE,
            FILS,
            1 as clazz_ 
        from
            TFILS 
    ) objethiber0_ 
where
    objethiber0_.ID=? 
    and (
        mod(objethiber0_.etatobjet,2)=0
    )

and son :

    select
        objethiber0_.ID as id1_14_0_,
        objethiber0_.ACTEURCREATION as acteurcreation2_14_0_,
        objethiber0_.ACTEURMODIFICATION as acteurmodification3_14_0_,
        objethiber0_.ACTEURSUPPRESSION as acteursuppression4_14_0_,
        objethiber0_.DATECREATION as datecreation5_14_0_,
        objethiber0_.DATEMODIFICATION as datemodification6_14_0_,
        objethiber0_.DATESUPPRESSION as datesuppression7_14_0_,
        objethiber0_.ETATOBJET as etatobjet8_14_0_,
        objethiber0_.PERE as pere9_14_0_,
        objethiber0_.FILS as fils1_8_0_ 
    from
        TFILS objethiber0_ 
    where
        objethiber0_.ID=? 
        and (
            mod(objethiber0_.etatobjet,2)=0
        ) 

Because the class is concrete and can be instantiated. The base class must be abstract if you don’t want the table.

That’s because the default inheritance strategy is SINGLE_TABLE as you can read in the @Inheritance annotation Javadoc.

Yes thanks.
What bothered me the most was the modeling of the denormalized table. But hibernate handles these cases well.

Ok I understood my misunderstanding!

The table TPERE is included in the table TFILS (denormalized), suddenly all the columns of TPERE are considered as in TPERE even if in the end the real table will be TFILS.