-->
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.  [ 8 posts ] 
Author Message
 Post subject: discriminator subquery
PostPosted: Thu Aug 25, 2005 3:47 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
Hi all,

I have an entity who's behaviour is determined by a 'category'. However, within a category we have many (>200) different sub-categories (which do not affect behaviour).

We let a user create an entity by first letting him choose the category and then choosing the sub-category. The sub-category is persisted and category is not.
This is an existing enterprise system, and I can not just alter the tables to allow this. :(

The discriminator should be the category, not the sub-category. Not in the least because we do not want to create hundreds of subclasses.

Therefor, is it possible to use a sub-query to determine the category instead of making it a column in the table? We have translation tables that will determine the category for every sub-category value.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 8:01 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I don't understand what you want to do; what will this "sub-query" do exactly ?
I assume that you want to say: "I have an graph of entities; and the type of an instance is determined by a 'category'" !?!

Can you give a pratical example (with a minimal graph and some usage code) ?

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 9:33 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Hi,
I think I know what TheShark wants - he has a 'discriminator' column containing values 1,2,3,4.....,200 but 1,2,3.....,50 means Class1 , 50..130 means Class2 and the rest Class3 (for example).
In my opionion it is not possible to create "calculated" discriminator because of one reason - discriminator MUST be read-write data, which cannot be in the case of calculated data. I'm afraid that if it is absolutly impossible to alter the data structure, you will have to resign from polymorphic approach here.

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 4:54 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
michal is exactly right. That is what I want, sorry if my explanation was not clear. :oops:

However, in my opinion, a calculated discriminator is possibly since it only needs to be calculated when read.. It does not need to be written. When the class is written (for instance class 1, but value 20), it also writes that value (20). So we only need to be able to translate the value 20 to Class1 at instantiation time. (using michals explanation here).

Although we have altered the data structure in the particular case, I'm not sure if I'm going to be able to do the same in other cases, so i'm still very interested in a reply! :lol:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 6:32 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
If ( 1, 2, 3, ..., 50 means Class1 ) then what is the difference between them (1, 2, 3, ..., 50) ?
And when do you use that difference?

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 10:54 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
There is no difference in behaviour. However, the difference is important for the application.
For instance, you can have only one of each at a given period in time.
Which means there can possibly be 50 Class1's per client.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 12:38 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
TheShark wrote:
There is no difference in behaviour. However, the difference is important for the application.
For instance, you can have only one of each at a given period in time.
Which means there can possibly be 50 Class1's per client.


Are you sure that you are not misusing the table-per-class-hierarchy mapping strategy ?

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 7:43 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
KPixel wrote:
Are you sure that you are not misusing the table-per-class-hierarchy mapping strategy ?


Yep, in the current situation, the chosen strategy seems correct. But, it doesn't matter, we have added the 'category' column so all is great now.


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