Discriminator by R4R Team

In the discriminator a restricted set of types can be used: string, character, integer, byte, short, boolean, yes_no, true_false.

<discriminator> element is required for polymorphic persistence using the table-per-class-hierarchy mapping strategy. discriminator declares a  column of the table. The discriminator column contains marker values that tell the persistence layer what subclass to instantiate for a particular row. 

<discriminator column="discriminator_column" type="discriminator_type" force="true|false" insert="true|false" formula="arbitrary sql expression"/>

1. column (optional - defaults to class): the name of the discriminator column.

2. type (optional - defaults to string): a name that indicates the Hibernate type

3. force (optional - defaults to false): "forces" Hibernate to specify the allowed discriminator values, even when retrieving all instances of the root class.

4. insert (optional - defaults to true): set this to false if your discriminator column is also part of a mapped composite identifier. It tells Hibernate not to include the column in SQL INSERTs.

5. formula (optional): an arbitrary SQL expression that is executed when a type has to be evaluated. It allows content-based discrimination.

Actual values of the discriminator column are specified by the discriminator-value attribute of the <class> and <subclass> elements.

The force attribute is only useful if the table contains rows with "extra" discriminator values that are not mapped to a persistent class. This will not usually be the case.

The formula attribute allows to declare an arbitrary SQL expression that will be used to evaluate the type of a row. 

For example:

<discriminator formula="case when CLASS_TYPE in ('a', 'b', 'c') then 0 else 1 end" type="intege.>

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!