-->
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: query on a component from a join-subclass
PostPosted: Thu May 05, 2011 4:45 am 
Newbie

Joined: Mon Feb 09, 2004 8:58 am
Posts: 4
Hi,
We use hibernate 3

We have a class of type A which includes a component of type Data with a set of Contexts

This way :
Code:
public class Context {
    protected String id;
    protected String name;
   
       <...>
}

Code:
public class Data {
       protected Set<Context> contexts;

       <...>
}

Code:
public class A{
    protected String id;
    protected String name;
    protected Data data;
              <...>
}

The mapping files are :
Code:
<hibernate-mapping >
   <class name="Context" table="CONTEXT" >
      <id type="string" name="id" column="CONTEXT_ID" length="20">
         <generator class="..." />
      </id>
      <property name="name" type="string">
         <column name="NAME" length="50" />
      </property>
   </class>
</hibernate-mapping>

and :
Code:
<hibernate-mapping >
   <class name="A" table="A">
      <id type="string" name="id" column="A_ID" length="20">
         <generator class="..." />
      </id>
      <property name="name" type="string">
         <column name="NAME" length="50" />
      </property>
      <component name="data">
         <set name="contexts" table="CONTEXT_A">
            <key column="A_FK" />
            <many-to-many class="Context" column="CONTEXT_FK" order-by="CONTEXT_ID asc"/>
         </set>
      </component>         
   </class>
</hibernate-mapping>


At the same time we have a sub class of type B
Code:
public class B extends A {

}

With a mapping file as :
Code:
<hibernate-mapping >
   <joined-subclass name="B" extends="A"
      table="B">
      <key column="B_ID" />
   </joined-subclass>
</hibernate-mapping>

when we write a HQL query this way :

Code:
select count(b) from B  as b left join b.data.contexts as context where context.name = :value


The query is correctly translated but an oracle exception is thrown due to a bad management of join :

select count(b0_.B_ID) as col_0_0_ from B b0_
inner join A b0_1_ on b0_.B_ID=b0_1_.A_ID
inner join CONTEXT_A contexts1_ on b0_1_.B_ID=contexts1_.A_FK
inner join CONTEXT context2_ on contexts1_.CONTEXT_FK=context2_.CONTEXT_ID
inner join A context2_1_ on context2_.CONTEXT_ID=context2_1_.A_ID
where context2_.NAME = ?

Error message is : ORA-00904: "B0_1_"."B_ID" : identificateur non valide
And it's true because the bold part of request must be b0_1_.A_ID because "contexts" set is part of component Data in A and not in B.

what'is wrong ?

thansk is advance


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.