-->
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: Collections mapping
PostPosted: Wed Dec 07, 2005 11:02 pm 
Beginner
Beginner

Joined: Sun Oct 16, 2005 3:07 am
Posts: 33
Location: Sydney
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 12:12 am 
Beginner
Beginner

Joined: Sun Oct 16, 2005 3:07 am
Posts: 33
Location: Sydney
I resolved this by using the composite-element tag. I'm not sure of the implications of using this tag. Are there any?


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.