Ummmm.....
You should use <one-to-many> or <many-to-many> <many-to-one> makes no sense at all..... jiesheng zhang <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Sent by: cc: [EMAIL PROTECTED] Subject: [Hibernate] should <many-to-one> be added to <bag><list>...? eforge.net 03/02/03 06:11 PM 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 ********************************************************************** Any personal or sensitive information contained in this email and attachments must be handled in accordance with the Victorian Information Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988 (Commonwealth), as applicable. This email, including all attachments, is confidential. If you are not the intended recipient, you must not disclose, distribute, copy or use the information contained in this email or attachments. Any confidentiality or privilege is not waived or lost because this email has been sent to you in error. If you have received it in error, please let us know by reply email, delete it from your system and destroy any copies. ********************************************************************** ------------------------------------------------------- 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