-->
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.  [ 6 posts ] 
Author Message
 Post subject: Simple inheritance mapping
PostPosted: Wed Jul 06, 2005 10:27 am 
Newbie

Joined: Wed Jul 06, 2005 10:21 am
Posts: 3
I have a class which is named "Product". I have other classes derived form class Product, which are "Book", "Car". I have a mapping for "Product" that has general properties for both "Book" and "Car". I want to use 3 different mapping files for "Product", "Book" and "Car". I need seperate files, because i will have many of "Product" inheritances.

how can i do this? how can i add properties of "Product" to "Book" mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:01 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
As Gavin would say, read this:

http://www.hibernate.org/ForumMailinglists/HowToAskForHelp

Then read this:

http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-declaration-subclass


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:20 pm 
Newbie

Joined: Wed Jul 06, 2005 10:21 am
Posts: 3
i should be more specific;

i dont want to write something to the parent mapping that points child class. once i wrote the parent class i will never touch it. i just want to define a class that extends the parent. is it possible?Although, i found no complex example related with this, i hope it is possible in a way.

i need something like;

<hibernate-mapping>
<class name="Book" table="book" extends="Product">
.......
</class>
</hibernate-mapping>

so the class Book will have all the properties of the class Product


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you would have read the documentation instead of "being more specific" you would have found out by now how exactly this works. In fact its the same syntax you just wrote.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:29 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Quote:
It is possible to define subclass, union-subclass, and joined-subclass mappings in separate mapping documents, directly beneath hibernate-mapping. This allows you to extend a class hierachy just by adding a new mapping file. You must specify an extends attribute in the subclass mapping, naming a previously mapped superclass. Note: Previously this feature made the ordering of the mapping documents important. Since Hibernate3, the ordering of mapping files does not matter when using the extends keyword. The ordering inside a single mapping file still needs to be defined as superclasses before subclasses. -- section 6.1.15


It even has an example:
Code:
<hibernate-mapping>
    <subclass name="DomesticCat" extends="Cat" discriminator-value="D">
         <property name="name" type="string"/>
    </subclass>
</hibernate-mapping>


Sometimes I think our exhausted resident hibernate gurus are a little tough on us newbies, but jeez, dude, read!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:50 pm 
Newbie

Joined: Wed Jul 06, 2005 10:21 am
Posts: 3
i am sorry about this. after eagles link i noticed subclass can do what i want.

in Chapter 9. inheritance mapping examples say "using <class>". subclass is always used as inner class. i thought subclass can not use as independent class.

sorry for wasting your time. i learned that "never be limited with the reference examples!". read whole reference document. :-)


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