File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes discriminator for multiple column values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "discriminator for multiple column values" Watch "discriminator for multiple column values" New topic
Author

discriminator for multiple column values

Franck McGeough
Greenhorn

Joined: Oct 27, 2005
Posts: 26
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Just out of curiosity.

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Franck McGeough
Greenhorn

Joined: Oct 27, 2005
Posts: 26
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: discriminator for multiple column values
 
Similar Threads
Parsing the String
Mapping Varchar to Number
MySQL table joining
validate an excelsheet entries using java code
Table-per-class mapping restrictions