This issue can't be edited

Because it belongs to an archived project. Jira admins can restore projects from the archive.

Discriminator column not supported with JOINED strategy

Description

Section 9.1.27 of the EJB3 persistence public draft says, "The DiscriminatorColumn annotation is used to define the discriminator column for SINGLE_TABLE and JOINED mapping strategies." But Hibernate ignores the DiscriminatorColumn annotation when the mapping strategy is JOINED; when a JOINED entity is persisted, its discriminator column is not included in the SQL "insert" statement, resulting in a not-null constraint violation if the discriminator column is marked NOT NULL in the database.

The JOINED strategy with discriminators is pretty ubiquitous in EJB3 sample code and tutorials out on the net, so lots of people are likely to run into this as they try out EJB3 for the first time. A few examples:

http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30inheritance/doc/how-to-ejb30-inheritance.html
http://www.solarmetric.com/Software/Documentation/4.0.0EA/docs/full/html/ejb3_overview_mapping_discrim.html
http://www.caucho.com/resin-3.0/amber/tutorial/cmp-inherit/index.xtp

Environment

Hibernate 3.1rc2, Hibernate Annotations 3.1b6

Activity

Show:

Steve Ebersole January 28, 2014 at 10:23 PM

I did eventually add this support : https://hibernate.atlassian.net/browse/HHH-6911#icft=HHH-6911

But really its more intended for compatibility with inferior providers that need the discriminator with joined inheritance...

Gérald Quintana July 29, 2009 at 1:51 PM

Using discriminator column with "joined" strategy used to work when we were using .hbm.xml files to describe ORM. Moreover it's clearly documentated:
http://docs.jboss.org/hibernate/stable/core/reference/fr/html/inheritance.html#inheritance-tablepersubclass-discriminator

SInce we moved to annotations instead of XML files, we can't do that anymore except using secondary tables but it's painful.

Sergey Generalov April 29, 2009 at 12:23 PM

4 years passed since this issue was opened.
Any changes?

"Status: Resolved Resolved
Resolution: Rejected "

Rejected? Why? This is very important functionality. Can anyone tell why this issue was skipped, please.

Constantine Voronin November 5, 2008 at 1:00 PM

I've the same problem with strategy=JOINED and Discriminator Values.
It's very important to me to have not null value of discriminator field, I use it in group queries.

Now I have to do in base classes something like:

public MyBase () {
// set the value of discriminator's field
kind = this.getClass().getSimpleName();
}

I think it is really ugly

Pavel  February 19, 2008 at 12:06 AM

It would be nice to see how the problem with the multiple joins is faced when the underlying DB has restriction on the number of joins one can execute in a single SQL? For instance MySQL seems to allow only 31 joins. What happens if the class hierarchy has more than 31 sub-classes?

Rejected

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Amit Kasher
Constantine Voronin
Emmanuel Bernard
Erwin Bolwidt
GavinG
Gérald Quintana
Ortwin Glück
Pavel

Affects versions

Priority

Created November 5, 2005 at 10:48 PM
Updated January 28, 2014 at 10:23 PM
Resolved November 6, 2005 at 12:46 AM