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