-->
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.  [ 5 posts ] 
Author Message
 Post subject: Table per subclass, using a discriminator
PostPosted: Mon Nov 28, 2005 12:51 pm 
Newbie

Joined: Wed Oct 12, 2005 7:33 pm
Posts: 4
Hibernate supports 3 basic inheritence mapping strategies - one is "Table per subclass, using a discriminator.

For example:

<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
<discriminator column="PAYMENT_TYPE" type="string"/>
<property name="amount" column="AMOUNT"/>
...
<subclass name="CreditCardPayment" discriminator-value="CREDIT">
<join table="CREDIT_PAYMENT">
<property name="creditCardType" column="CCTYPE"/>
...
</join>
</subclass>
<subclass name="CashPayment" discriminator-value="CASH">
<join table="CASH_PAYMENT">
...
</join>
</subclass>
<subclass name="ChequePayment" discriminator-value="CHEQUE">
<join table="CHEQUE_PAYMENT" fetch="select">
...
</join>
</subclass>
</class>

Does NHibernate support such a strategy? If not, what is the best way to accomplish this type of inheritence?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 10:01 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHibernate 1.0 is the port of Hibernate 2.1, so it supports "table-per-class-hierarchy" (your case), "table-per-subclass" and "table-per-concrete-class" strategies.

Read subclass and joined-subclass documentation.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 11:05 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
KPixel, as i understood it's not exactly his case. jpflick1 want to store parts of the class in different tables and use discriminator column to decide, what tables must be joined.
This strategy is not supported now. You can either use discriminator and store all the class hierarchy in one table, or use joins, but no discriminators then.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 2:00 pm 
Newbie

Joined: Wed Oct 12, 2005 7:33 pm
Posts: 4
Thanks for the responses. xor, you are correct in what I was wanting to accomplish. Combining the the <subclass> and <join> elements to make a <joined-subclass> looses some of the flexibility that is in Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 3:54 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
jpflick1 wrote:
Combining the the <subclass> and <join> elements to make a <joined-subclass> looses some of the flexibility that is in Hibernate.


Just to be clear, the <joined-subclass> is not a hack that NHibernate did that reduced funtionality compared to Hibernate. Hibernate 2.1.x has <joined-subclass>. Hibernate 3 has the <join> element you want to use. NHibernate currently matches Hibernate 2.1.x. Getting NHibernate up to Hibernate 3.x functionality is one of the next major goals, but it hasn't happened yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.