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.  [ 3 posts ] 
Author Message
 Post subject: How to reference a superclass column in correlated subquery?
PostPosted: Fri Apr 04, 2008 5:36 pm 
Newbie

Joined: Fri Apr 04, 2008 5:05 pm
Posts: 3
Hi,

I am having difficulties getting Hibernate to use the correct table alias for a correlated subquery.

In the example below, I want the correlated subquery in the formula for the lookthruTicker to reference the alias of the superclass (Security), not the outer class (Bond) for the owner_system_code column.

Is there any way to reference the superclass?
Can I set the alias explicitly and reference that value?

Not specifying the alias defaults to the Bond table's alias
Any attempt to specify an alias (i.e. super, parent, base etc) is invalid.

Mapping documents:
Code:
<hibernate-mapping package="com.blah.db">
    <class name="Security" table="security" dynamic-insert="true" dynamic-update="true" lazy="true" mutable="true">
        <id name="securityId" column="security_id" type="integer" unsaved-value="null"></id>
        <discriminator column="security_subclass_type" type="string"/>
        <version name="version" column="version" type="int"/>
       
        <property name="ownerSystemCode" column="owner_system_code" type="string" not-null="true" length="4"/>
        <property name="ticker" column="ticker" type="string" not-null="true" length="50"/>
       
        <subclass name="BondSecurity" discriminator-value="BOND">
            <join table="bond">
                <key column="security_id" on-delete="cascade"/>

                <property name="someId" column="some_id" type="integer" not-null="false"/>
                <property name="lookthruSomeId" column="lookthru_some_id" type="integer" not-null="false"/>
               
                <property name="lookthruTicker"
                          type="string"
                          update="false"
                          insert="false"
                          formula="(

             select s.ticker
             from security s, bond b
             where
             b.security_id = s.security_id and
             b.some_id = lookthru_some_id and
             <!-- ********************************************** -->
             <!-- ***** This is the line that causes grief ***** -->
             s.owner_system_code = owner_system_code)"

                          access="field"
                          lazy="false"/>
            </join>
        </subclass>
    </class>
</hibernate-mapping>


The generated SQL (show_sql=true):
What this generates is
Code:
select ....
(select s.ticker
from security s, bond b
where b.security_id = s.security_id
and b.some_id = security0_1_.lookthru_some_id
and s.owner_system_code = security0_1_.owner_system_code) as formula3_0_
from security security0_
left outer join bond security0_1_ on security0_.security_id=security0_1_.security_id
where ....


The generated SQL (show_sql=true):
Whereas what I want it to generate is
Code:
select ....
(select s.ticker
from security s, bond b
where b.security_id = s.security_id
and b.some_id = security0_1_.lookthru_some_id
and s.owner_system_code = security0_.owner_system_code) as formula3_0_
from security security0_
left outer join bond security0_1_ on security0_.security_id=security0_1_.security_id
where ....


The difference is very subtle. In the first example it joins to security0_1_ and in the second example it joins to security0_

Hibernate version: 3.1.3

Name and version of the database you are using: Sybase 12.5.3


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 2:57 pm 
Newbie

Joined: Fri Apr 04, 2008 5:05 pm
Posts: 3
Any ideas?

Craig


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Tue Apr 08, 2008 10:15 am 
Newbie

Joined: Tue Oct 10, 2006 3:27 pm
Posts: 4
I am experiencing the same problem. There were a few fixes in the 3.2.6 release that should take care of this problem, but I am using that version and am still encountering problems. Be sure to post if you find a resolution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.