--- [EMAIL PROTECTED] wrote: > > Ummmm..... > > > You should use <one-to-many> or <many-to-many> > > <many-to-one> makes no sense at all..... I INDEED need a <many-to-one> under <bag>! My Top-level (not nested) <bag> table has a key column and element column (integer). However the element column is a foreign key (many-to-one) to another table (B in the example below). E.g: BAG TABLE TABLE B key integer id name ..... 1 1 1 "name1" .... 1 2 2 "name2" .... 1 3 3 "name3" .... 2 3 2 2 Here I wants the bag element(Java object) is type of B, not just the integer. Following current DTD, I have to encapsulate the <composite-element> which has a single <many-to-one> under the <bag>. The question is why I can not use <many-to-one> directly under <bag>?
"On a second thought <many-to-one>/<one-to-one> should be allowed anywhere <property>/<element> is allowed. For <property>/<element>, One columnis used to produce an instance of primitive type. For<many-to-one>/<one-to-one> one column (and another table) is used to produce a user-defined type." Is this statement is correct? This is a abstract example. My previous example(below) is a concrete example I encoutered in my application. Thanks jason > > > > > > 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 towrap the > AddressType object. The AddressTypeWrapperhas only > one property: the > AddressType object. Sohere the > AddressTypeWrapper is really an > artifactclass required for hibernate mapping only, > not fromobject model. > What I really wants is that the collection element > istype of AddressType, > not AddressTyepWrapper. Themapping 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 doesnot have > <many-to-one> element. Is there any other > consideration why > <many-to-one> isnot allowed here? or Can I just > modify the DTD and usethe > <many-to-one> directly under <bag>.On a second > though > <many-to-one>/<one-to-one> shouldbe allowed anywhere > <property>/<element> > is allowed.For <property>/<element>, One column > produce aninstance 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. > === message truncated === __________________________________________________ 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