These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Discriminator From a Joined Table
PostPosted: Thu Jun 23, 2005 6:18 pm 
Newbie

Joined: Wed Jun 22, 2005 6:33 pm
Posts: 8
I'm using the table-per-class-hierarchy design, as explained in the documentation. However, my discriminator is part of a joined table. I'm not sure how to accomplish this.

The easiest way to explain would be to extend the "Payment" example from the docs. The example has the discriminator (PAYMENT_TYPE) as a field in the payments table. I want to store my payment types in a separate table and join against them, but still be able to use the CashPayment, ChequePayment, etc. values as a discriminator.

Any ideas?

Thanks

Norman


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
try using a subselect in a discriminator <formula>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 12:47 pm 
Newbie

Joined: Wed Jun 22, 2005 6:33 pm
Posts: 8
gavin wrote:
try using a subselect in a discriminator <formula>


Thanks. I tried this, and it seems to work. With one hitch...

Hibernate is dynamically renaming my tables (Devices --> device0_), so I have no way of writing a formula that works. For instance...

Code:
(SELECT DeviceTypes.TypeName FROM DeviceTypes WHERE DeviceTypes.TypeID = device0_.DeviceTypeID)

... works for some queries but not others.

Any ideas? Thanks,

Norman[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 1:28 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
The formula should be straight SQL that you would write if you were using something other than hibernate.

i.e. we do the same thing as you're describing with:

@hibernate.discriminator formula="(select wt.WORKFLOW_EVENT_CLASS from WORKFLOW_TYPE wt where wt.WORKFLOW_TYPE_ID = WORKFLOW_TYPE_ID)"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 1:30 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I think the "missing" part from my query would be the last WORKFLOW_TYPE_ID should probably be this.WORKFLOW_TYPE_ID but I believe that hibernate will just imply this anyways.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 2:14 pm 
Newbie

Joined: Wed Jun 22, 2005 6:33 pm
Posts: 8
VampBoy wrote:
I think the "missing" part from my query would be the last WORKFLOW_TYPE_ID should probably be this.WORKFLOW_TYPE_ID but I believe that hibernate will just imply this anyways.


Perhaps that's my problem. I'm using MySQL, and I don't believe it supports any magic keyword to refer to the outer table. In your example, "this" is your keyword. In MySQL, I would have to refer to the table name by it's name.

Since Hibernate is generating the query on the fly, and refers to the table by an alias, I cannot predict what table name to use!

Any other ways around this? I realize this is perhaps a DB-specific problem, but surely I'm not the first to tackle this.

Thanks for any ideas,

Norman


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 26, 2005 2:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate parses the given formula and inserts its own aliases where approporiate. Any unaliased identifier is assumed to belong to the outer table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.