From: Patrick S. <psa...@co...> - 2002-07-04 17:20:47
|
Hi Guys, I've recently got back onto my hibernate project and like it _very_ much. I am having a little difficulty nesting a class in another - perhaps someone can easily pinpoint where I'm going wrong. 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. When I retrieve a ProductSpecification object I want to get the corresponding panelSpecification objects also. Question: What have I got wrong with my mapping file? 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. Though the manual is detailed, I reckon a few more examples of common things done would answer 95% of newbie questions. I am using version 1.0rc2 . Any tips much appreciated. Thanks, Patrick. ======================== Mapping file================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "file://localhost//usr/local/hibernate-1.0rc2/src/cirrus/hibernate/hibernate-mapping.dtd"> <hibernate-mapping> <class name="com.psaunders.project.ProductSpecification" table="product_specification" select="all"> <id name="productTypeId" column="product_type_id" type="long"> <generator class="sequence"/> </id> <property name="longDesc" column="long_desc"/> <property name="shortDesc" column="short_desc"/> <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> <collection name="panelName" column="panel_name" role="panels" /> <collection name="productTypeId" column="product_type_id" role="panels" /> <collection name="zOrder" column="z_order" role="panels" /> </class> <class name="com.psaunders.project.PanelSpecification" table="panel_specification" select="all"> <id name="id" column="uid" type="long"> <generator class="sequence"/> </id> <property name="productTypeId" column="product_type_id"/> <property name="panelName" column="panel_name"/> <property name="zOrder" column="z_order"/> </class> </hibernate-mapping> ================================================= ========== DDL for schema ================ drop table panel_specification drop table product_specification drop sequence hibernate_sequence create table panel_specification (panel_name VARCHAR(255), product_type_id INT4, uid INT8 not null, z_order INT4, primary key (uid)) create table product_specification (long_desc VARCHAR(255), product_type_id INT8, short_desc VARCHAR(255), primary key (product_type_id)) alter table panel_specification add constraint panel_specificationFK0 foreign key (product_type_id) references product_specification create index panel_specificationIDX1 on panel_specification (product_type_id) ======================================== |