-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to mapping inheritance
PostPosted: Fri Jun 24, 2011 6:29 am 
Newbie

Joined: Fri Jun 24, 2011 6:22 am
Posts: 3
Hi
i'm begginer in NHibernate, im trying to learn a basic mapping methods and I have a big problem with them.

I mean:
I have two classes

Code:
class Customer : Person{
     public int CustomerId;
     public string FirstName;
}


and
Code:
class Person{
    public int PersonId
    public string LastName;
}


How can I map this inheritance?
I'm trying to:
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="APP" auto-import="true">
  <class name="APP.Customer, APP" lazy="false">
    <id name="CustomerId" access="field" type="int">
      <generator class="increment" />
    </id>
    <property name="FirstName" access="field" column="FirstName"/>
    <joined-subclass name="Person">
      <key column="PersonId" />
      <property name="LastName"/>
    </joined-subclass>
  </class>
</hibernate-mapping>

but I have a exception that "could not load a Person type in assemply APP"

I don't know how to do it.
Help me please.


Top
 Profile  
 
 Post subject: How to mapping inheritance
PostPosted: Wed Aug 10, 2011 5:07 am 
Newbie

Joined: Wed Aug 10, 2011 4:45 am
Posts: 3
Hi..Hibernate supports the three basic inheritance mapping strategies like...

table per class hierarchy

table per subclass

table per concrete class

In addition, Hibernate supports a fourth, slightly different kind of polymorphism:

implicit polymorphism

example:The ordering inside a single mapping file still needs to be defined as superclasses before subclasses.
<hibernate-mapping>
<subclass name="DomesticCat" extends="Cat" discriminator-value="D">
<property name="name" type="string"/>
</subclass>
</hibernate-mapping>

Table per class hierarchy 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">
<property name="creditCardType" column="CCTYPE"/>
...
</subclass>
<subclass name="CashPayment" discriminator-value="CASH">
...
</subclass>
<subclass name="ChequePayment" discriminator-value="CHEQUE">
...
</subclass>
</class>

_________________
Cegonsoft


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