|
Hibernate may be better in other respects, but those other so-called "inferior" implementations can handle the following object model much more cleanly than Hibernate can: @Entity(access=FIELD) @Entity(access=FIELD) @Entity(access=FIELD) @Entity @Entity Without using discriminator values, how can Hibernate possibly distinguish between instances of BottomLevel1 and BottomLevel2, since they have no properties (and thus no tables of their own to outer-join with)? The only way to model this with Hibernate, as far as I can tell, is to use the SINGLE_TABLE strategy and put @SecondaryTable on all the subclasses that have properties – at which point you also have to annotate each and every property with @Column(secondaryTable="whatever"). Which kind of defeats the purpose of EJB3's "configure by exception" philosophy. A discriminator column can also be used to choose the right subclass for a lazy proxy. Now in a lazy OneToOne the proxy is always the topmost class, which is bad, because there is no way of telling the real class behind the proxy! I strongly suggest to revisit this issue and use an optional discriminator column as a hint. See http://forum.hibernate.org/viewtopic.php?p=2319629#2319629 discriminator is not gonna help your case. I don't understand Gavin's stance on this issue. It leaves users out in the cold who are using a legacy database; the only way to get around it is to not use annotations for the superclass and all subclasses. In addition to that, even if a discriminator column never gives any performance bonuses, it still makes the database model more resilient. If for some reason (dbas mucking about the database by hand, other apps interfering with the direct use of sql) data ends up in multiple subclass tables, a discriminator column makes it possible to clean up the database, since it is the judge on what the intended subclass was. Please change the three lines of code and make it possible to configure discriminator columns with joined subclasses using hibernate annotations. Patch welcome, but it's probably more 3k lines than 3 I'd like to add another possible requirement for discriminator column support. If you have a discriminator column, you can have it inside DB constraints, and achieve constraints in which subclasses participate as different entities. Example: I have the following entities: A { B extends A { C extends A { I need the following constraint: I don't want to allow (more than 1 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? I've the same problem with strategy=JOINED and Discriminator Values. 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 4 years passed since this issue was opened. "Status: Resolved Resolved Rejected? Why? This is very important functionality. Can anyone tell why this issue was skipped, please. Using discriminator column with "joined" strategy used to work when we were using .hbm.xml files to describe ORM. Moreover it's clearly documentated: SInce we moved to annotations instead of XML files, we can't do that anymore except using secondary tables but it's painful. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EJB3 does NOT require use of discriminators with JOINED mapping strategies. It is allowed for inferior implementations of the JOINED mapping strategy which require a discriminator. Hibernate does not need a discriminator because Hibernate is better than these other inferior implementations.