-->
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.  [ 1 post ] 
Author Message
 Post subject: Joined Subclass with multiple levels generates wrong SQL
PostPosted: Fri Dec 05, 2008 1:22 am 
Newbie

Joined: Fri Dec 05, 2008 1:02 am
Posts: 1
Location: Switzerland
Hello,

While doing a refactoring where we changed the inheritence strategy we discovered that the generated SQL does not return the same results as before (unit test).

The mapping:
Code:
<joined-subclass abstract="true" name="SRP" table="BK9_T_SYS_RESILIENCE_PLAN">
    <key column="PLAN_ID" />
    <joined-subclass name="BCASRP" table="BK9_T_SYS_RESILIENCE_PLAN_BCA" >
        <key column="PLAN_ID" />
        <property column="IS_EXTERNAL_SYSTEM" name="externalSystem" type="boolean" />
    </joined-subclass>
    <joined-subclass name="INVSRP" table="BK9_T_SYS_RESILIENCE_PLAN_INV">
        <key column="PLAN_ID" />
        <property column="IS_EXTERNAL_SYSTEM" name="externalSystem" type="boolean" />
    </joined-subclass>
</joined-subclass>


The criteria:
Code:
criteria = HibernateUtilImpl.instance().getSession().createCriteria(SRP.class);
    if (query.getExternalSystem() != null) {
        criteria.add(Restrictions.eq("externalSystem", query.getExternalSystem()));
    }


The generated SQL:
Code:
select * FROM bk9_t_sys_resilience_plan this_ INNER JOIN bk9_t_plan this_1_
      ON this_.plan_id = this_1_.plan_id
      LEFT OUTER JOIN bk9_t_sys_resilience_plan_bca this_2_
      ON this_.plan_id = this_2_.plan_id
      LEFT OUTER JOIN bk9_t_sys_resilience_plan_inv this_3_
      ON this_.plan_id = this_3_.plan_id
      LEFT OUTER JOIN bk9_t_system_dependency systemdepe2_
      ON this_.plan_id = systemdepe2_.srp_plan_id
      WHERE this_2_.is_external_system = 1;


The SQL we whould expect:
Code:
select * FROM bk9_t_sys_resilience_plan this_ INNER JOIN bk9_t_plan this_1_
      ON this_.plan_id = this_1_.plan_id
      LEFT OUTER JOIN bk9_t_sys_resilience_plan_bca this_2_
      ON this_.plan_id = this_2_.plan_id
      LEFT OUTER JOIN bk9_t_sys_resilience_plan_inv this_3_
      ON this_.plan_id = this_3_.plan_id
      LEFT OUTER JOIN bk9_t_system_dependency systemdepe2_
      ON this_.plan_id = systemdepe2_.srp_plan_id
      WHERE this_2_.is_external_system = 1 or this_3_.is_external_system = 1;


At first while using Hibernate 3.2.6, the two subclasses have been joined with a INNER JOIN which resulted in results returned from the first joined subclass only. But with Hibernate 3.3.1, the subclasses are now joined with an LEFT OUTER JOIN which is correct. Now the where clause is wrong. For some reason, the generated SQL contains the where-clause only from one subclass instead of both. Since we are querying for the superclass and not for a superclass, we expect that the SQL should contain both subclasses in the where clause.

We can resolve the issue by moving the common attributes to the superclass, but this is no option since this will break the business domain.

I am thinking about filing a bug against this issue - or do I miss something?


Regards,

Cyrill


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

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.