thanks alot deigo :) On Fri, Apr 2, 2010 at 8:51 PM, Diego Mijelshon <[email protected]>wrote:
> Not only is *theoretically* possible to map arbitrary stuff to > discriminator values: I'm *actually* doing it :-) > All you have to do is use a formula for the discriminator. Example: > > <class name="Guy" discriminator-value="G"> <id ... >...</id> > <discriminator formula="*case when Income > 1000000 then 'R' when > Income < 10000 then 'P' else 'G' end*"/> <property name="Income"/> > <subclass discriminator-value="R" name="RichGuy"/> <subclass > discriminator-value="P" name="PoorGuy"/> </class> > > Anyway, when using inheritance like this, you need to keep some things in > mind: > > - When lazily loading instances of Guy, the object type will inherit > from Guy, NOT RichGuy/PoorGuy. Virtual method calls will work as expected, > but type comparisons/conversions (i.e. "guyInstance is RichGuy" or > "guyInstance as PoorGuy") will fail. Read > > http://ayende.com/Blog/archive/2009/09/03/answer-the-lazy-loaded-inheritance-many-to-one-association-orm.aspx > - A persistent instance will not change its type while it's referenced > by the session. So, if you increase a poor guy's income to 10000, you'll > only get a PoorGuy instance in a different session OR by evicting and > reloading it. > > > Diego > > > On Fri, Apr 2, 2010 at 13:28, nadav s <[email protected]> wrote: > >> lets say i have Employee which is a concrete class with the properties >> Id >> Type >> >> and i have CoolEmployee and MoronEmployee that extend Employee >> >> now i have many employee types and i want type=1 to generate CoolEmployee >> and type=2 to generate MoronEmployee. >> there are alot of other possible values, for instance, 3 is manager and 4 >> is Cleaning guy, and i want all of these other values to generate the >> Employee class >> >> Do i need an extra column to discriminate between the classes or can i >> somehow say that Employee is the default class of a not-found value and use >> the type column? >> >> (i don't have a mapping because it is just a theoritical question :) ) >> >> btw, another thing i was wondering about but couldn't google an answer is >> if it is currently possible to set range of values for discrimination >> (similar to the previous question) >> lets say that i have the sub classes RichGuy, PoorGuy both extend Guy >> and i wanna have the RichGuy subclass generated when the Income column is >> more than 1,000,000 >> if the Income is between 10,000 to 1,000,000 its just a Guy >> and less than 10,000 is a PoorGuy >> >> could this be mapped? >> i see a big problem with this scenario because if the Income property is >> updatebly by the application, we could have a PoorGuy that his Income just >> became >> high enough that he should become just a Guy >> but if the Income property isn't updatebly it might make sense >> >> again, it is just a theoretical question. >> >> thanks. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<nhusers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
