-->
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 produces select-statement with id__ and id0_
PostPosted: Mon Aug 23, 2004 7:11 pm 
Newbie

Joined: Mon Aug 23, 2004 6:46 pm
Posts: 1
Hibernate version: Hibernate: 2.1.6, 9.8.2004

Hello,
I used hibernate the first time and set up a relation between cds and tracks
(one cd could have many tracks). The java-classes are CD.java and Track.java.

Mapping documents:
Code:
<hibernate-mapping>
    <class name="de.rassmann.cdstore.entities.CD" table="cds">
        <id name="id" type="integer" column="id" unsaved-value="null" >
            <generator class="identity"/>
        </id>
        <property name="cddbid"/>
        <property name="title"/>
        <property name="artist"/>
        <property name="category"/>
        <list name="tracks" lazy="true" inverse="true">
            <key column="cd"/>
         <index column="track"/>
            <one-to-many class="de.rassmann.cdstore.entities.Track"/>
        </list>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="de.rassmann.cdstore.entities.Track" table="tracks">
        <id name="id" type="integer" column="id" unsaved-value="null" >
            <generator class="identity"/>
        </id>
   <many-to-one name="cd" class="de.rassmann.cdstore.entities.CD" column="cd" not-null="true"/>
        <property name="track"/>
        <property name="song"/>
    </class>
</hibernate-mapping>


So far, everything works fine. I can collect my cds and the corresponding list of tracks.

Code between sessionFactory.openSession() and session.close():
Code:
            Query query = session.createQuery( "from CD as cd where cd.artist = :artistsearch" );
           
            query.setString( "artistsearch", "Beastie Boys" );
            List result = query.list();
            assertTrue("no datasets found", result.size() > 0);

            Iterator it = result.iterator();
            while (it.hasNext()) {
                CD cd = (CD)it.next();
                List tracks = cd.getTracks();
                assertNotNull( "no tracks", tracks );
                assertFalse( "no tracks", tracks.isEmpty() );
            }


Name and version of the database you are using: mysql 4.0.18-log

The query produces the correct results with lazy selects, but I am unsure whether the select-statement is OK: every attribut of "tracks" is collected twice.

Code:
Hibernate: select cd0_.id as id, cd0_.cddbid as cddbid, cd0_.title as title, cd0_.artist as artist, cd0_.category as category from cds cd0_ where (cd0_.artist=? )
[...]
Hibernate: select tracks0_.cd as cd__, tracks0_.id as id__, tracks0_.track as track__, tracks0_.id as id0_, tracks0_.cd as cd0_, tracks0_.track as track0_, tracks0_.song as song0_ from tracks tracks0_ where tracks0_.cd=?


Isn't that a waste of bandwidth?
Is this the correct behavior of hibernate?
Is the mapping OK?

Thx, Tom


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.