wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes discriminator on two columns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "discriminator on two columns" Watch "discriminator on two columns" New topic
Author

discriminator on two columns

jani basha
Greenhorn

Joined: Oct 23, 2008
Posts: 8
hi,
can anybody tell me whether we can use discriminator on two columns.....in hibernate
that means i want to fetch data basing on two columns
[ October 29, 2008: Message edited by: jani basha ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Why not. Please provide what you have, at least the SQL, to elaborate a bit more.
jani basha
Greenhorn

Joined: Oct 23, 2008
Posts: 8
i got situation like this. i have two columns as follows

col1 --- col2

fax --- in
fax --- out
scan --- done
scan --- notdone

i have to diffrentiate rows basing on these two columns.
so here i have to use col1 and col2 as descriminators.
how can i do this??
jani basha
Greenhorn

Joined: Oct 23, 2008
Posts: 8
Need More Info???
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Normally, a discriminator will just be an arbitrary value since the state of an entity would not normally also change its type (and discriminators are never exposed to the application). Have you really got entities that need to behave this way? Your example look (to my uninformed eye) like state for one object type, not different types.

I think you could do it with a formula, since the hibernate-mapping dtd allows either a column or a fomula in a discriminator. You would need to come up with some formula based on these field values that returns an evaluable value.

You could also investigate the Hibernate <any /> mapping. This gives a mechanism to map polymorphic associations based on more than one field.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
I don't think you can have a discriminator on two columns. I say this based on the validation schema for the mapping xml.

Discriminators are used only to distinguish between 2 child classes (or implementations of the same interface) when you map a class hierarchy, so I can't think of any situation in which you would need 2 columns to fulfill such a basic function.

Maybe you should recheck if what you need in your situation is a discriminator.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I say this based on the validation schema for the mapping xml

Is there a schema for mapping files? I thought Hibernate only used DTDs (and the DTD allows a discriminator to use a formula)?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I have never used it myself, but I think it can be achieved, as Paul said, by using formula. For example,



instead of



The example is taken from the hibernate reference docs.
Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
indeed. i was missing the formula attribute. sry for that. my bad.
however, i'm still not sure why you would need such a complicated method for such a basic task.
jani basha
Greenhorn

Joined: Oct 23, 2008
Posts: 8
thanks for your replies....

yes we may achieve this by using formula attribute.
but while fetching the data if i want to retrieve only the records which are of status "fax out". In this scenario where i have to use criteria as fallows

Criteria criteria = session.createCriteria(data.class,"fax");
by using this i may not get the required result.

it will be fine if i can pass one more param as "out" that means if discrmininator="col1,col2,col3...."
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If "fax out" is part of your discriminator you can't use it as Criteria because, as mentioned above, discriminators are hidden from your application.

You can select all of the types you've defined to be identified by this discriminator though.

This all sounds a little suspect - isn't this just the state of one type rather than multiple types? Multi-value discriminators are (I'd imagine) very unusual things.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: discriminator on two columns
 
Similar Threads
table per class
Implementing Inheritance with Hibernate...
[Hibernate] composite-id and table-per-hierarchy
InheritanceType.JOINED and DiscriminatorColumn
Using the discriminator column in QL queries and primary keys