This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
We have a table that stores interesting configuration information. I need to subclass based on two column values. It appears that I can do that with Hibernate 3 but I'm confused by the syntax required.
For example, I have two columns : SUBSYTEM and ATTRIBUTEVAL. If the SUBSYSTEM = 'LICENSING' AND the ATTRIBUTEVAL = 'LICENSEKEY' then I want to have a License object.
Is there some reference material for the syntax of the formula discriminators? I've been searching through the Reference Manual but it doesn't explain it in a way that makes the syntax sensible to me.
You make the License object, you map it, when you go to get them, use the Criteria object where the two fields are part of the where clause, then all the objects that come back will match and be license records.
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.