posted 19 years ago
Perhaps I'm misunderstanding or not explaining myself well. There are various Configuration objects stored in a table. A License, an InstallDescription, a FolderActions, a URLDescriptor, etc. etc. The base object for me is a Configuration object. If the row stores some interesting information and requires some special behaviors that make it seem "object worthy" I'll derive a class from Configuration and provide the behavior and properties. So far, so good.
This is really straightforward with Hibernate if there is a single column in the table that tells how to map a row to a class.
However, in this particular case, there are two column values that together indicate which class to map to. Conceptually I need to specify the equivalent of an if statement that maps these things.
Obviously I could just query and retrieve the 1 particular record and "know" that its a License record. However, I have possibly hundreds of these configuration records in the table. I may want to cache them in memory as a Configuration list or return them a list of them as a result of a request from the business layer. I may want to call Configuration methods that are overridden by the derived object whilst running thru a list of Configuration objects.
It seems like this capability was something that was added to Hibernate 3. I just can't figure out how to specify it properly in the mapping.
In order to just avoid the problem for now I've created a derived field based on a formula, concatenated the fields together and discriminated based on that. This works to some extent but I'd really like to know how to do the discriminator based on multiple column values given that it is a part of the Hibernate system.
Does this make more sense now?