-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using an alias in <class where=""/> attribut
PostPosted: Fri Sep 23, 2005 12:46 pm 
Beginner
Beginner

Joined: Fri Mar 19, 2004 7:21 am
Posts: 20
Hi there,
I have a legacy table that is holding two classes.. I am trying to use the "where" attribute in the hbm to restrict my entities. This is working perfectly if I hardcode the aliasname. However, when I start using <subclass/> the aliasname gets changed by hibernate.. I need some kind of string replacement in the where clause so that hibernate will put the alias name in for me at runtime.. Is this possible? Might there be another way for me to work around this legacy table?

Here is the working mappings..

Code:
<class name="AiDocument" table="document"
      where="aidocument0_.document_id = (
            select min(d.document_id) from document d
            where d.ai_class = aidocument0_.ai_class and
            d.ai_subclass = aidocument0_.ai_subclass and
            d.document_no = aidocument0_.document_no and
            d.year = aidocument0_.year
            )">

<class name="AiDocumentTranslation" table="document"
      where="aidocument0_.document_id not (
            select min(d.document_id) from document d
            where d.ai_class = aidocument0_.ai_class and
            d.ai_subclass = aidocument0_.ai_subclass and
            d.document_no = aidocument0_.document_no and
            d.year = aidocument0_.year
            )">


Regards,
Damon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 12:59 pm 
Newbie

Joined: Fri Sep 23, 2005 10:57 am
Posts: 2
I was litterally just about to post almost exactly the same question, although I don't have subclass to deal with, I expect that syntax that includes a hardcoded alias will also foul up if a complex query occurs referencing more than one instance (requiring both a foo0_ and a foo1_ alias).

However in my case I am not doing a nested select, but accessing a column which is an Oracle Object type, and omiting the alias definately doesn't work (not supprising).

In my case the only alternative I see is to do a bunch of conditional logic to see if the values returned are ones that our application should be paying attention to (The DB is shared across several applications)

I'm not sure I can think of a case where the second alias name would be needed, but I'm all too aware that the fact that I can't think of it isn't a very good test :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 1:55 pm 
Beginner
Beginner

Joined: Fri Mar 19, 2004 7:21 am
Posts: 20
Thanks for the reply, glad to know I'm not alone. ;-)

I have actually found a temp workaround though how long it holds up I'm not sure.. My subclass looked like this..

Code:
<subclass name="ActionDocument" discriminator-value="ACTION">

    <many-to-one name="parentActionDocument" column="serial_id"
        lazy="true" class="ActionDocument"
        formula="case when serial_id = 0 then null else serial_id end" />

If I change the class to AiDocument then it generates the same alias as the primary class and my where clause works.. It does still create the correct ActionDocument instance though.

Code:
<subclass name="ActionDocument" discriminator-value="ACTION">

    <many-to-one name="parentActionDocument" column="serial_id"
        lazy="true" class="AiDocument"
        formula="case when serial_id = 0 then null else serial_id end" />

So I will proceed with this hack until I run into the next brick wall. ;-)

Damon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 4:50 pm 
Newbie

Joined: Fri Sep 23, 2005 10:57 am
Posts: 2
Well, I did this:

Code:
* @hibernate.class table="oss_mas_accounts" where="ossmasacco0_.business_area.osow='X'"


and got

Code:
select

ossmasacco0_.mas_acc_code as x0_0_

from

oss_mas_accounts ossmasacco0_

where

ossmasacco0_.business_area.osow='X'

order by  ossmasacco0_.acc_nbr


But then I also noticed that I was also getting

Code:
select

this.fee_rule_code as fee_rule1_1_,
this.class as class1_,
this.version as version1_,
this.rule_name as rule_name1_,
this.application_time as applicat5_1_,
this.fee_amount as fee_amount1_,
this.ledger_code as ledger_c7_1_,
this.effective_date as effectiv8_1_,
this.expiration_date as expirati9_1_,
this.refundable as refundable1_,
this.user_id as user_id1_,
ossmasacco1_.mas_acc_code as mas_acc_1_0_,
ossmasacco1_.acc_nbr as acc_nbr0_,
ossmasacco1_.acc_name as acc_name0_,
ossmasacco1_.business_area as business4_0_

from

oss_osw_fee_rule this,
oss_mas_accounts ossmasacco1_

where

this.application_time=? and
this.effective_date<? and
this.expiration_date>? and
this.ledger_code=ossmasacco1_.mas_acc_code(+)


Which appears to be selecting the fee rule and the account, missing the where clause, so it would be possible to get a result for a fee rule that referenced an account in the wrong business area.

I'm ditching the where clause for now, but I would really like to know if The second is(was? I'm using 2.1.6) a bug, or just a me missing something. I would also like to know if there is a solution to the original question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 7:28 am 
Beginner
Beginner

Joined: Fri Mar 19, 2004 7:21 am
Posts: 20
Quote:
I would also like to know if there is a solution to the original question.


Me too.. Any Hibernate guys want to jump in on this one? ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.