From: Gavin_King/Cirrus%<CI...@ci...> - 2002-07-05 00:16:24
|
>In a nutshell, there is a one-to-many relationship from >class productSpecifcation to class panelSpecification. > >I want to model this using a nested collection. >.... >Question: What have I got wrong with my mapping file? > ><list role="panels" table="panel_specification" lazy="false" cascade ="none" > > <key column="product_type_id" type="long" /> > <index column="product_type_id" type="long"/> > <element column="id" type="long"/> ></list> Should be something more like: <list role="panels" table="panel_specification" lazy="false" cascade="none" > <key column="product_type_id" type="long"/> <index column="panel_index"/> <one-to-many class="com.psaunders.project.PanelSpecification"/> </list> The index column holds the index of the panel in the list. If you don't care about panel ordering, you should use a set instead of a list. oh .. .and cascade defaults to "none", so you can leave it off. > <property name="productTypeId" column="product_type_id"/> Are you sure you don't want a <many-to-one> here? It actually looks like you might *really* be trying to do is map a bidirectional one-to-many association. (In which case you need a <set>, not a <list>.) Have a look at the section on bidirectional associations in the programming guide. > Also, I don't understand the use of the <element> tag > in the declaration of my <list>. The docs are a bit > vague on this. The <element> tag is used for collections of _values_ not for associations between _entities_. (ie. if you wanted to map a list of strings or dates.) >Though the manual is detailed, I reckon a few more examples >of common things done would answer 95% of newbie questions. I know, i'm actually gradually improving this. Just last night I added an new example section to the collections documentation. Its up at the main website if that helps.... Unfortunately mapping collections is kinda complicated at first. This is because Hibernate supports * collections of values (including components) as well as associations * indexed collections like maps + lists * subcollections / toplevel collections so when a new user comes along and wants to know how to map a simple one-to-many association, they have to sort through a whole bunch of more complicated stuff..... hope that helps Gavin P.S. its better to post these kind of questions to the users forum on the sourceforge project page. |