-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Table per subclass with discriminator and annotations
PostPosted: Sun Feb 05, 2012 1:30 am 
Newbie

Joined: Fri Feb 03, 2012 11:14 am
Posts: 5
Hibernate supports using a discriminator with the table-per-subclass inheritance strategy but only using xml (see link below). It would be nice if this was also supported when using annotations; anything supported in xml should be supported with annotations and vice-versa. Are there plans to support this in the future?


http://docs.jboss.org/hibernate/orm/3.3 ... criminator

-kor


Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Fri Feb 10, 2012 6:17 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi kor,

where it is written that Hibernate supports discriminator with the table-per-subclass inheritance strategy only using xml ?
I use sucessfully table-per-subclass inheritance strategy with discriminators using annotations only:

Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@DiscriminatorOptions(force=true)
@DiscriminatorValue("Animal")
public class Animal ...

@Entity
@DiscriminatorOptions(force=true)
@DiscriminatorValue("Cat")
public class Cat extends Animal ...


I use hibernate 3.6.2 but I'm pretty sure it works with 3.3 too (the annotations DiscriminatorOptions and DiscriminatorValue are not necessary)


Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Thu Mar 01, 2012 11:46 pm 
Newbie

Joined: Fri Feb 03, 2012 11:14 am
Posts: 5
Thank you for replying pb00067,

Below is the hibernate configuration of what I am trying to achieve using annotations. According to the link I put in the original posting, this Inheritance
Strategy is "Table per subclass: using a discriminator". Notice that classes AbcNodeX and AbcNodeY map to the same table; they are distinguished from each other using the discriminator.
Unfortunately, we are working with a legacy database so I cannot change the database tables.

With annotations, when I run a query for a Node which should be of type AbcNodeX, Hibernate is returning a Node of type AbcNodeY.


Code:

<hibernate-mapping>
<class name="com.achme.Node" table="NODE">
  <id column="nodeid" name="nodeid" type="long"/>
  <discriminator column="defId" force="false" insert="true" not-null="true"/>
  <property generated="never" lazy="false" name="name" type="java.lang.String">
   <column name="NAME"/>
  </property>
<subclass discriminator-value="12345"
   name="com.achme.AbcNodeX" select-before-update="false">
   <join fetch="select" table="ABC_NODE">
   <key column="nodeid"/>
    <property generated="never" lazy="false" name="type" type="string">
     <column length="60" name="type"/>
    </property>
</join>
  </subclass>
<subclass discriminator-value="4567"
   name="com.achme.AbcNodeY" select-before-update="false">
   <join fetch="select" table="ABC_NODE">
    <key>
     <column name="nodeid"/>
    </key>
    <property generated="never" lazy="false" name="type" type="string">
     <column length="60" name="type"/>
    </property>
   </join>
  </subclass>
</class>




I am using hibernate 4.0

Any help is appreciated.

Thank you.


Last edited by kor on Fri Mar 02, 2012 9:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Fri Mar 02, 2012 3:11 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi kor,

sorry, I did confound "Table per subclass" with "Table per concrete class" (=InheritanceType.TABLE_PER_CLASS).

As far as I can see, table-per-subclass inheritance strategy with discriminators is in fact not feasible using annotations only
(I tested with Hibernate4.1.0).


Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Fri Mar 02, 2012 9:35 am 
Newbie

Joined: Fri Feb 03, 2012 11:14 am
Posts: 5
Thank you for the quick response. Are you aware of future support of this feature?


Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Fri Mar 02, 2012 9:40 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I searched a little bit in the Hibernate-Jira but found nothing in this direction straightaway.


Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Fri Mar 02, 2012 11:13 pm 
Newbie

Joined: Fri Feb 03, 2012 11:14 am
Posts: 5
I've opened HHH-7144 for this issue. Hopefully we will get some traction.


Top
 Profile  
 
 Post subject: Re: Table per subclass with discriminator and annotations
PostPosted: Sat Mar 03, 2012 7:20 pm 
Newbie

Joined: Fri Feb 03, 2012 11:14 am
Posts: 5
pb00067,

It looks like there is a jira ticket already open for this issue. HHH-6911.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.