• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

discriminator for multiple column values

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Franck McGeough
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic