Question

I am taking a table per subclass approach to map some data using hibernate. Typically at the database layer I would introduce a type column in the abstract table and it's subtables, which would enforce that an abstract record can only relate to a subrecord of a matching type. However from looking at various resources it seems to state that the hibernate discriminator is used for legacy databases. Does this mean I am taking the wrong approach?

Was it helpful?

Solution

Table Per (Sub)Class means you have one table per class and no abstract table. Thus a discriminator is not needed. If you have Single Table or Joined inheritance, then you'd need a discriminator.

Edit: actually, Hibernate's Table Per Subclass seems to be the Joined inheritance strategy. However, this is stated by the documentation:

Hibernate's implementation of table per subclass does not require a discriminator column.

OTHER TIPS

As stated above, Hibernate table per subclass does not require a discriminator.

According to the same source: "... If you want to use a discriminator column with the table per subclass strategy, you can combine the use of subclass and join ..."

See section 9.1.3 in http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tablepersubclass

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top