-->
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: table per concrete class
PostPosted: Thu Jun 28, 2007 1:43 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Hello,

I have a class "Product" which inherits from an abstract class called "Item".

Item contains the following property :
public CategoryOfProduct ParentCategory;

Product contains the following property :
public string Name;

I would like to map those class to a single table called "Products" which contains both fields : ParentCategory and Name.

I think I should use the table per concrete class inheritance mapping strategy, but I have some difficulties to write the mapping file. Here is the code :

<class name="Product" table="Products">
<id name="Id">
<column name="Id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex" />
</id>
<any name="CategoryOfProduct " meta-type="class" id-type="Int64">
<column name="Id"/>
<column name="ParentCategory"/>
</any>
<property name="Name" />
</class>

Could you show me where I've made a mistake please ?

Thank you in advance,

mathmax


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 2:32 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
To start, if both base and subclass map to the same table, the correct strategy is table-per-hierarchy. See http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/inheritance.html#inheritance-strategies


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 2:48 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
In fact I've an other object type : "CategeryOfProduct" which inherits "Item" too. This class is mapped to a table "Categeries". So I've two tables for each sublclass and a parent abstract class that contains properties mapped to fields from each of those both tables.
I've read many times the chapter of your link, and in this case, I think I should use the table per concrete class strategy, shouldn't I ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 1:59 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Probably, but note that what you wrote in your reply is not what you wrote in your first post. You made no mention that CategoryOfProduct inherited from Item as well. Also, in your first post, you should be using a <many-to-one> where you have an <any>.

Your desired architecture seems to be shifting with each message, as you reveal more information in response to each question. You need to craft a complete picture of what it is you intend or what your problem is before you ask for assistance. I know there is a language barrier as well: please make a serious effort to get a hold of the French language Hibernate 2.1.7 docs, and try to read those side by side with the latest NH documentation.

Good luck!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 4:10 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Quote:
you should be using a <many-to-one> where you have an <any>


Do you mean I should replace the tag "any" by the "many-to-one" or just insert a "many-to-one" tag in the "any" tag ? In the documentation, they say to use a "any" tag but they don't explain where to put it.
I'll have a look at the hibernate documentation, but I don't know the java language. If you could give me a short example of mapping it would be very nice.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 1:31 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Nobody knows how to use the <any> tag ?


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.