-->
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: Unknown column on subclass object
PostPosted: Wed Mar 03, 2010 3:26 am 
Newbie

Joined: Thu Jan 01, 2009 10:57 am
Posts: 7
Hi,

I am trying to fetch an object of a subclass. But it throws Unknown column error, even though the particular column is available in the subclass table. If i add the same in the super class table it is not throwing the error. But it won't work properly. Please help me resolve this. Let me know, If you want to see the details of my pojo and hbm mapping files.

Thanks,
Nava


Top
 Profile  
 
 Post subject: Re: Unknown column on subclass object
PostPosted: Wed Mar 03, 2010 4:46 am 
Newbie

Joined: Wed Mar 03, 2010 3:36 am
Posts: 5
Please attach your POJO class and mapping file.


Top
 Profile  
 
 Post subject: Re: Unknown column on subclass object
PostPosted: Wed Mar 03, 2010 11:55 am 
Newbie

Joined: Thu Jan 01, 2009 10:57 am
Posts: 7
Below are my pojos

Code:
class SuperA{}

abstract class SubA extends SuperA{}

class SubB extends SubA{
   SubC subC;
}

class SubC extends SubA{
   SubB subB;
}


And below are my mapping files

Code:
<hibernate-mapping>
   <class name="SuperA" table="SuperA">
      <id column="ID" name="id" type="java.lang.Long">
         <generator class="increment" />
      </id>
      <discriminator column="DISCRIMINATOR" force="false"
         insert="true" length="30" not-null="true" type="java.lang.String" />
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <subclass abstract="true" discriminator-value="SubA"
      extends="SuperA" name="SubA"
      select-before-update="false">
      <join fetch="select" table="SubA">
         <key on-delete="cascade">
            <column name="ID" />
         </key>
      </join>
   </subclass>
</hibernate-mapping>

<hibernate-mapping>
   <subclass discriminator-value="SubB"
      extends="SubA" name="SubB"
      select-before-update="false">
      <one-to-one class="SubC"
         cascade="all" name="subC" property-ref="subB" />
      <join fetch="select" table="SubB">
         <key on-delete="cascade">
            <column name="ID" />
         </key>
      </join>
   </subclass>
</hibernate-mapping>

<hibernate-mapping>
   <subclass discriminator-value="SubC"
      extends="SubA" name="SubC"
      select-before-update="false">
      <join fetch="select" table="SubC">
         <key on-delete="cascade">
            <column name="ID" />
         </key>
      </join>
      <many-to-one cascade="save-update" class="SubB"
         name="subB" not-null="true">
         <column name="SUB_B_ID" />
      </many-to-one>
   </subclass>
</hibernate-mapping>



Now i am trying "from SubB" HQL and it throws the below error.
Unknown column 'subc_1_.SUB_B_ID' in 'where ......

If i add the SUB_B_ID column in SuperA and set the same value as in SubC then all are working fine. Basically when "from SubB" HQL is compiled to sql query it is not joining SubA and SubC for the one-to-one mapping. Even if i change the one-to-one mapping to one-to-many i get into same issue.


Top
 Profile  
 
 Post subject: Re: Unknown column on subclass object
PostPosted: Wed Mar 03, 2010 8:56 pm 
Newbie

Joined: Wed Mar 03, 2010 8:27 pm
Posts: 9
Location: Russia, Perm
I've got the same problem.

In my case:
Code:
<hibernate-mapping>
  <class name="xxx.Client" table="clients">
    <id column="id" name="id" type="int">
      <generator class="increment"/>
    </id>
    <property column="email" name="email" type="java.lang.String"/>
    <property column="name" name="name" type="java.lang.String"/>
    <property column="password" name="password" type="java.lang.String"/>
    <one-to-one cascade="all" class="xxx.ClientMainAccount" property-ref="client" name="mainAccount" />
  </class>
</hibernate-mapping>

Code:
<hibernate-mapping>
    <class discriminator-value="0" name="xxx.Account" table="accounts">
        <id column="id" name="id" type="int">
            <generator class="increment"/>
        </id>
        <discriminator column="type_id" type="integer"/>
        <property column="currency_id" name="currencyId" type="int"/>
        <property column="amount" name="amount" type="double"/>
        <subclass discriminator-value="10" name="xxx.ClientMainAccount">
            <join table="client_main_accounts">
                <key column="account_id"/>
                <many-to-one cascade="all" class="xxx.Client" column="client_id" name="client" not-null="true" />
            </join>
        </subclass>
        <subclass discriminator-value="11" name="xxx.ClientAccount">
            <join table="client_accounts">
                <key column="account_id"/>
                <many-to-one cascade="all" class="xxx.Client" column="client_id" name="client" not-null="true" />
            </join>
        </subclass>
    </class>
</hibernate-mapping>

Hibernate generates:
Quote:
select
client0_.id as id4_1_,
client0_.email as email4_1_,
client0_.name as name4_1_,
client0_.password as password4_1_,
clientmain1_.id as id5_0_,
clientmain1_.currency_id as currency3_5_0_,
clientmain1_.amount as amount5_0_,
clientmain1_1_.client_id as client2_6_0_
from
clients client0_
left outer join
accounts clientmain1_
on client0_.id=clientmain1_.client_id
and clientmain1_.type_id=10
left outer join
client_main_accounts clientmain1_1_
on clientmain1_.id=clientmain1_1_.account_id
where
client0_.id=?

Caused by: org.postgresql.util.PSQLException: ERROR: column clientmain1_.client_id does not exist :(

But correct in my case is something like this:
Code:
    select
        client0_.id as id4_1_,
        client0_.email as email4_1_,
        client0_.name as name4_1_,
        client0_.password as password4_1_,
        client0_.registration_date as registra5_4_1_,
        t.id as id5_0_,
        t.currency_id as currency3_5_0_,
        t.amount as amount5_0_,
        t.client_id as client2_6_0_
    from
        clients client0_
    left outer join
    (
   select * from
      accounts clientmain1_
   left outer join
      client_main_accounts clientmain1_1_
        on clientmain1_.id=clientmain1_1_.account_id
        where clientmain1_.type_id=10
    ) t
     on client0_.id=t.client_id

    where
        client0_.id=1

I need hibernate to join superclass and subclass before joining with one-to-one


Top
 Profile  
 
 Post subject: Re: Unknown column on subclass object
PostPosted: Thu Mar 04, 2010 2:18 am 
Newbie

Joined: Thu Jan 01, 2009 10:57 am
Posts: 7
Exactly. I too need hibernate to join superclass and subclass before joining for one-to-one (or one-to-many).

Thanks,
Nava


Top
 Profile  
 
 Post subject: Re: Unknown column on subclass object
PostPosted: Thu Mar 04, 2010 4:41 am 
Newbie

Joined: Thu Jan 01, 2009 10:57 am
Posts: 7
This is an issue with Hibernate 3.3.2 GA. Please look at below jira defect.

http://opensource.atlassian.com/project ... e/HHH-1015


Top
 Profile  
 
 Post subject: Re: Unknown column on subclass object
PostPosted: Fri Mar 05, 2010 9:34 am 
Newbie

Joined: Wed Mar 03, 2010 8:27 pm
Posts: 9
Location: Russia, Perm
Has 3.5.0-CR-2 this problem? Or it was fixed?


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.