Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3
I have 3 tables - Location, LocationGroup and OrderedLocations.
A location can belong to many location groups and a location group can have many locations. The ordered locations table is to hold the collection but has one extra column in it, which is why I have a bean and mapping document for it. The mapping for it means that a LocationGroup has one to many OrderedLocations and Location also has one to many OrderedLocations. The orderedlocations table has a primary key to avoid compsite-keys
Is my mapping correct? When I add the OrderedLocation object to a LocationGroup band try to save the LocationGroup object, hibernate tells me that the OrderedLocation object is transient. The OrderedLocation object is to link LocationGroups and Locations.
Mapping documents:
<class name="LocationBean" table="TWR_RETAIL_LOCATION">
<id name="id" column="LOCATION_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">TWR_SEQ_RETAIL_LOCATION</param>
</generator>
</id>
<property name="name" column="NAME" type="java.lang.String" not-null="true"/>
<property name="title" column="TITLE" type="java.lang.String" not-null="true"/>
<property name="abbreviation" column="ABBREVIATION" type="java.lang.String" not-null="true"/>
<property name="deleted" column="DELETED" type="boolean" not-null="true"/>
<property name="createDate" column="CREATED" type="java.util.Date" not-null="true"/>
<!-- The location groups for the location -->
<set name="locationGroups" inverse="true">
<key column="LOCATION_ID"/>
<one-to-many class="OrderedLocationsBean"/>
</set>
<!-- The offers for the location -->
<set name="offers" inverse="true">
<key column="LOCATION_ID"/>
<many-to-many column="OFFER_ID" class="OfferBean"/>
</set>
</class>
<class name="LocationGroupBean" table="TWR_RETAIL_LOCATION_GROUP">
<id name="id" column="LOCATION_GROUP_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">TWR_SEQ_RETAIL_LOCATION_GROUP</param>
</generator>
</id>
<!-- properties -->
<property name="name" column="NAME" type="java.lang.String" not-null="true"/>
<property name="title" column="TITLE" type="java.lang.String" not-null="true"/>
<property name="siteId" column="SITE_ID" type="int" not-null="true"/>
<property name="deleted" column="DELETED" type="boolean" not-null="true"/>
<property name="createDate" column="CREATED" type="java.util.Date" not-null="true"/>
<!-- The site that this Location Group belongs to
<one-to-one name="site" class="Site"
cascade="none" column="site_id" unique="true"/> -->
<!-- The locations for this location group -->
<set name="locations" table="TWR_RETAIL_ORDERED_LOCATIONS">
<key column="LOCATION_GROUP_ID"/>
<one-to-many class="OrderedLocationsBean"/>
</set>
</class>
<class name="OrderedLocationsBean" table="TWR_RETAIL_ORDERED_LOCATIONS">
<id name="id" column="ORDERED_LOCATIONS_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">TWR_SEQ_RETAIL_ORD_LOCATIONS</param>
</generator>
</id>
<many-to-one
name="locationGroup"
class="LocationGroupBean" />
<!-- column="location_group_id"/> -->
<many-to-one
name="location"
class="LocationBean" />
<!-- column="location_id"/> -->
<property name="order" />
</class>
Oracle 8