-->
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: Many to many , retrieving the association class ...
PostPosted: Tue Aug 17, 2004 6:45 pm 
Newbie

Joined: Wed Jul 07, 2004 4:38 am
Posts: 5
Hibernate version: 2.1

Hello,
First of all, sorry I know there are lot of posts about many to many problems but I have been surfing through the forum and i didn't find an answer.

So i have two classes A and B with an association class AB (which is a component element of A).

The thing is I want to get all the data of the AB table without any criteria and outside the scope of A or B. I know I can do that by simply using jdbc and connect to the AB table. But If I want to use hibernate , How can I perform that?

I tried to do some tries by using the examples of James Elliot book("a Devellopers book" chapter 5) .
Here are the two mapping files :
Album.hbm
Code:
<hibernate-mapping>
  <class name="com.oreilly.hh.Album" table="ALBUM">
    <meta attribute="class-description">
      Represents an album in the music database, an organized list of tracks.
      @author Jim Elliott (with help from Hibernate)
    </meta>
    <id name="id" type="int" column="ALBUM_ID">
      <meta attribute="scope-set">protected</meta>
      <generator class="native"/>
    </id>
    <property name="title" type="string">
      <meta attribute="use-in-tostring">true</meta>
      <column name="TITLE" not-null="true" index="ALBUM_TITLE"/>
    </property>
    <property name="numDiscs" type="integer"/>
   
<list name="tracks" table="ALBUM_TRACKS" cascade="all">
      <meta attribute="use-in-tostring">true</meta>
      <key column="ALBUM_ID"/>
      <index column="POSITION"/>
      <composite-element class="com.oreilly.hh.AlbumTrack">
        <many-to-one name="track" class="com.oreilly.hh.Track" cascade="all">
          <meta attribute="use-in-tostring">true</meta>
          <column name="TRACK_ID"/>
        </many-to-one>
        <property name="disc" type="integer"/>
        <property name="positionOnDisc" type="integer"/>
      </composite-element>
    </list>
  </class>
</hibernate-mapping>


track.hbm :
Code:
<hibernate-mapping>
  <class name="com.oreilly.hh.Track" table="TRACK">
    <meta attribute="class-description">
      Represents a single playable track in the music database.
      @author Jim Elliott (with help from Hibernate)
    </meta>
    <id name="id" type="int" column="TRACK_ID">
      <meta attribute="scope-set">protected</meta>
      <generator class="native"/>
    </id>
    <property name="title" type="string">
      <meta attribute="use-in-tostring">true</meta>
      <column name="TITLE" not-null="true" index="TRACK_TITLE"/>
    </property>
    <property name="filePath" type="string" not-null="true"/>
    <property name="playTime" type="time">
      <meta attribute="field-description">Playing time</meta>
    </property>
/class>
</hibernate-mapping>


So then When I generated the schema , a association table "Albumtracks" is created, and the codegen create the AlbumTrack.java file.
I tried to create a AlbumTrack.hbm file but with no success (and because I am also a newbie).
So If someone could tell me how to write the AlbumTrack.hbm or any solution to get the data of the albumtrack table it would be fantastic !
thank you in advance.
Sebi


Top
 Profile  
 
 Post subject: Hi
PostPosted: Wed Aug 18, 2004 12:39 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
First of all, I have a weak memory of having read that "Developer's handbook" is full of errors and not the best choice regarding Hibernate reading. I would recommend "Hibernate in Action", I've bought it myself and it's very useful reading. The e-book edition is actually quite affordable.

Secondly: IF you want to be able to query your AB-table directly, why not make it an entity? That would require a separate .hbm.xml-file, and you still would have to map it as a collection both from A and B.

Your option ( if you don't want to map AB an entity) is to use queries against A or B with JOIN clauses.


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.