Home > OS >  How to extend @Entity from commons lib?
How to extend @Entity from commons lib?

Time:08-11

I would like to extend an @Entity from a library that I don't have control of:

//commons package that I don't have control of
@Entity(name = TABLE_NAME)
public class CommonEntity {
    public static string TABLE_NAME = "common_entity";

    //like 30 fields with @Column annotations, hibernate validations etc
}

But how? I tried as follows, which fails:

//it's on a different database, just the schema should be extended
@Entity(name = CommonEntity.TABLE_NAME)
public class CustomEntity extends CommonEntity {
    //some more fields
}

Result:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException:
   Schema-validation: missing column [dtype] in table

As a result, I only want to have a single common_entity table extended with my custom fields. I don't plan to store CommonEntity objects directly to the table.

Is that possible? Would I somehow have to create that magical dtype column myself?

CodePudding user response:

At the end I simply let hibernate create the dtype column, so I can at least inherit all configuration from the commons entity, while only drawback is to have one "unneccessary" column.

  • Related