Greetings. Forgive me if this has been asked before - I did try the local search feature and google, but neither provided an answer, so I'll just dive in.
I am building an Orcale XE database to hold information about lego parts (we won't discuss how big a geek that makes me) and there is a many to many relationship between the part (such as block 1x1 or plate 4x8) and the set it belongs to (such as X-Wing Starfighter). A set, obviously, has many parts, and each part can belong to more than one set.
The tables involved are PARTS, SETS, and a cross table called SET_PARTS.
I have the hibernate mappings declared for PARTS and SETS, and I already have the many to many definition in the Sets class declared (getParts()).
What I would like to do is include the reverse mapping in the Parts class (getSets()). My question is: Will this cause issues in the application, or is Hibernate smart enough not to load all the parts for all the sets that I am loading by calling getSets (i.e. I could see this crashing the application with an infinite loading sequence, so I am wondering if there is something built into Hibernate that prevents it).
My current hbm files are below - they're fairly short. The mapping from parts to sets is the one I am concerned about adding.
Any assistance would be great.
Thanks.
PARTS
Code:
<hibernate-mapping package="com.legolibrary.hibernate">
<class name="Parts" table="PARTS">
<id name="id" type="long" column="PART_ID" >
<generator class="sequence" >
<param name="sequence">PART_ID_SEQ</param>
</generator>
</id>
<property name="legoid" column="LEGO_OFFICIAL_PART_CODE" type="string"/>
<property name="description" column="DESCRIPTION" type="string"/>
<many-to-one name="color"
column="COLOR_REF_ID"
class="com.legolibrary.hibernate.ReferenceData"
not-null="true"
foreign-key="PART_COLOR_FK"
lazy="false" />
<set name="sets" table="SET_PARTS" cascade="all">
<key column="SET_PART_ID" />
<many-to-many column="SET_ID" class="com.legolibrary.hibernate.Sets" />
</set>
</class>
</hibernate-mapping>
SETS
Code:
<hibernate-mapping package="com.legolibrary.hibernate">
<class name="Sets" table="SETS">
<id name="id" type="long" column="SET_ID" >
<generator class="sequence" >
<param name="sequence">SET_ID_SEQ</param>
</generator>
</id>
<property name="legoid" column="LEGO_OFFICIAL_SET_NUM" type="string"/>
<property name="name" column="NAME" type="string"/>
<set name="parts" table="SET_PARTS" cascade="all">
<key column="SET_PART_ID" />
<many-to-many column="PART_ID" class="com.legolibrary.hibernate.Parts" />
</set>
</class>
</hibernate-mapping>