I have one usage scenario as below: The classes could be like this. public class Person { ... List Addresses; //A list of Address objects. } public class Address { ... List types; //A list of AddressType object } public class AddressType { long typenum; String typename; }
The database schema could be like this. creat table addressType ( typenum varchar(20) primary key, typename varchar(40) not null ); /* * Table models a collection of address type. */ create table addressTypes ( collectionID integer, type integer, constraint FK_ADDRESSTYPE_TO_STRING foreign key (type) references addresstype (typenum) ); create sequence seq_ats; create table person ( id integer primary key, ... ); create table address ( personid integer not null, ... types integer, /* The type references the collectionID in the AddressTypes above */ constraint FK_ADDRESS_TO_PERSON foreign key (companyid) references person (id) ); The mapping file is like this <hibernate-mapping> <bag role="addressTypes" table="addressTypes"> <generated-key type="long" column="collectionID"> <generator class="sequence"> <param>seq_ats</param> </generator> </generated-key> <composite-element class="AddressTypeWrapper"> <many-to-one name="type" column="type" class="AddressType"/> </composite-element> <!-- here I use one component class AddressTypeWrapper to wrap the AddressType object. The AddressTypeWrapper has only one property: the AddressType object. So here the AddressTypeWrapper is really an artifact class required for hibernate mapping only, not from object model. What I really wants is that the collection element is type of AddressType, not AddressTyepWrapper. The mapping could be like this: <many-to-one name="type" column="type" class="AddressType"/>---<many-to-one>directly under <bag>. However this is not allowed by the DTD since bag does not have <many-to-one> element. Is there any other consideration why <many-to-one> is not allowed here? or Can I just modify the DTD and use the <many-to-one> directly under <bag>. On a second though <many-to-one>/<one-to-one> should be allowed anywhere <property>/<element> is allowed. For <property>/<element>, One column produce an instance of primitive type. For <many-to-one>/<one-to-one> one column (and a table) is used to produce a user-defined type. --> </bag> <!-- map for AddressType --> <class name="AddressType" table="AddressType"> <id name="typenum" type="long"> ... </id> <property name="typename" column="typename"/> </class> <!-- map for Person --> <class name="Person" table="person"> ... <!--person has a list of Address --> <bag name="addresses table="address"> <key column="personid"/> <composite-element> ... <!-- references to the top-level collection --> <collection name="types" column="types" role="addressTypes"/> </composite-element> </bag> </class> </hibernate-mapping> Thanks jason __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel