0

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?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • [vladmihalcea inheritance](https://vladmihalcea.com/the-best-way-to-use-entity-inheritance-with-jpa-and-hibernate/) could definitely be a good start. However, without control over the parent entity, it might be harder/impossible to get the mapping right. I also found [this](https://access.redhat.com/solutions/4081211), but it is only for redhat subscribers, which I am not, but it has the same error message as you – XtremeBaumer Aug 02 '22 at 08:55
  • I also found [this answer](https://stackoverflow.com/a/27597030/7109162) which suggests that `The name of the discriminator column in hibernate defaults to "DTYPE"` and you are not defining any inheritance yet – XtremeBaumer Aug 02 '22 at 09:04
  • 1
    My impression is that the `CommonEntity` should be annotated as `@MappedSuperclass` for inheritance to work. Since it is not under your control, you should be able to override this setting in orm.xml. – Nikos Paraskevopoulos Aug 02 '22 at 09:31
  • I also found [this answer](https://stackoverflow.com/a/12570643/2560836). – Chris311 Aug 03 '22 at 09:39

1 Answers1

0

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.

membersound
  • 81,582
  • 193
  • 585
  • 1,120