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.  [ 7 posts ] 
Author Message
 Post subject: Inheritance mapping : per concrete class strategy
PostPosted: Fri Oct 26, 2007 10:17 am 
Newbie

Joined: Fri Oct 26, 2007 9:50 am
Posts: 4
Hello,

I have 3 classes : P, S1 and S2.
The classes S1 and S2 extends the class P. In my database, I have just 2 table for the classes S1 and S2.

So, I would know how I do the mapping for the classes S1 and S2 to use Nhibernate's Polymorphic queries (From P).

I read the doc and understand that this case is the "per-concrete-class" strategy but I do not understand the use of the <any> tag.

Can you explain me how to map this ?

Thanks


Top
 Profile  
 
 Post subject: Inheritance mapping : per concrete class strategy
PostPosted: Mon Oct 29, 2007 9:22 am 
Newbie

Joined: Fri Oct 26, 2007 9:50 am
Posts: 4
Nobody have any ideas about this ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 11:32 am 
Beginner
Beginner

Joined: Thu Oct 25, 2007 3:45 am
Posts: 22
I personally use Table per class hierarchy strategy. I have never used Table per concrete class, but in the book "Hibernate in action" for this strategy is written:
"This mapping strategy doesn't require any special Hibernate mapping declaration: Simply create a new <class> declaration for each concrete class, specifying a different table attribute for each. We recommend this approach (only) for the top level of your class hierarchy, where polymorphism isn't usually required"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 5:28 am 
Newbie

Joined: Fri Oct 26, 2007 9:50 am
Posts: 4
vivaeinstein wrote:
"This mapping strategy doesn't require any special Hibernate mapping declaration: Simply create a new <class> declaration for each concrete class, specifying a different table attribute for each. We recommend this approach (only) for the top level of your class hierarchy, where polymorphism isn't usually required"


Ok thanks for the reply, but when I execute a query like "From P", I have this error :
"in expected: <end-of-text> (possibly an invalid or unmapped class name was used in the query) [from P]".

The aim of Table per concrete class startegy is execute query like this (From P) without use the children class in the query, isn't he?

If someone have any ideas... I take it !!!


Top
 Profile  
 
 Post subject: Inheritance mapping : per concrete class strategy
PostPosted: Fri Nov 09, 2007 11:57 am 
Newbie

Joined: Fri Oct 26, 2007 9:50 am
Posts: 4
up !


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 10, 2007 12:06 am 
Newbie

Joined: Mon Jun 04, 2007 8:44 pm
Posts: 8
Can you post your mapping file?

You should have a mapping for S1 and S2, and any collections that reference P should be use the <any> element.

Because P doesn't actually map to a table you can't query "from P". Which rows would you be retrieving?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 10, 2007 4:53 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
sentiadave wrote:
Can you post your mapping file?

You should have a mapping for S1 and S2, and any collections that reference P should be use the <any> element.

Because P doesn't actually map to a table you can't query "from P". Which rows would you be retrieving?


I think what the original poster is saying is that the values are duplicated between tables. Really what the poster wants is two queries, but does not want to have to type out two queries.

I would recommend writing two separate queries and then merging the results together. This is what NHibernate would do for you anyway. There is no SQL that can be written to return columns of varying types and quantities from two different tables in a single query.

Now, what you state should actually work. See the NHibernate documentation: http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#queryhql-polymorphism. It states that you should be able to query on any object or interface and then it will automatically turn that in to multiple queries. Are you sure your query is written correctly?

That being said maybe it would have been a superior approach to use 3 tables for this mapping. The base table would contain all items which were common to both element (directly mapping the base class) while the two other tables would contain the items specific to the subtypes.


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