Hibernate Inheritance and Discriminators

I was looking into the “single table per hierarchy” method of mapping inheritance with Hibernate and found out something new about how to declare the discriminator.

With a standard discriminator, you need a separate column in this method to tell Hibernate what type of object can be found in this row. In some cases it’s easy to have this extra column but in some cases you don’t have the control you would like over the structure of the data in the database.

If you can’t have a separate discriminator column, you can use the @DiscriminatorFormula annotation to pass in a sql fragment that Hibernate will use to determine the class of a particular row of data stored with this method.

See the Hibernate Annotations reference on inheritance for more information.


You can leave a response, or trackback from your own site.

Leave a repsonse

  1. * Required fields