-->
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.  [ 2 posts ] 
Author Message
 Post subject: Generated query containing duplicate columns
PostPosted: Wed Sep 02, 2009 4:26 am 
Newbie

Joined: Tue Sep 01, 2009 11:57 am
Posts: 2
I am facing a issue with the query generated by hibernate to load from database.

SELECT THIS_.ID AS ID25_1_,
THIS_.NAME AS NAME25_1_,
OFFICES2_.LEGAL_ENTITY_ID AS LEGAL3_3_,
OFFICES2_.ID AS ID3_,
OFFICES2_.ID AS ID27_0_,

OFFICES2_.NAME AS NAME27_0_
FROM CUSTOMER_MASTER.LEGAL_ENTITIES THIS_
LEFT OUTER JOIN CUSTOMER_MASTER.OFFICES OFFICES2_ ON THIS_.ID = OFFICES2_.LEGAL_ENTITY_ID

Why is hibernate generating query with duplicate reference to offices2_.id ?

My hbm file for legal_entities table is -

Code:
<hibernate-mapping>
    <class name="LegalEntity" table="LEGAL_ENTITIES" schema="CM" lazy="false">
        <id name="id" type="long">
            <column name="ID" precision="22" scale="0"/>
            <generator class="sequence">
                <param name="sequence">legal_entities_seq</param>
            </generator>
        </id>
        <property name="name" type="string">
            <column name="NAME"/>
        </property>
        <bag name="offices" cascade="none" fetch="join" inverse="true" lazy="false" >
            <key column="LEGAL_ENTITY_ID"/>
            <one-to-many class="Office"/>
        </bag>
    </class>
</hibernate-mapping>


And hbm for office is -

Code:
<hibernate-mapping>
    <class name="Office" table="OFFICES" schema="CM" lazy="false">
        <id name="id" type="long">
            <column name="ID" precision="22" scale="0"/>
            <generator class="sequence">
                <param name="sequence">offices_seq</param>
            </generator>
        </id>
        <property name="name" type="string">
            <column name="NAME"/>
        </property>
    </class>
</hibernate-mapping>


Last edited by asdhoke on Fri Sep 04, 2009 4:44 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Generated query containing duplicate columns
PostPosted: Fri Sep 04, 2009 4:43 am 
Newbie

Joined: Tue Sep 01, 2009 11:57 am
Posts: 2
Hello,

Looks like the way hibernate code works is, it adds columns from the joined table and it adds the same columns again if type join is LEFT_OUTER_JOIN. (The logic is in selectFragment() method of OneToManyPersister class)
Looks like it is a bug but im not sure if there is any other purpose behind this logic.

Any idea ?


Thanks,
Amey


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