From: Paul S. <pau...@ne...> - 2002-02-14 05:12:22
|
Hi, When I have a one-to-many in an object model, it usually gets implemented as a collection in the "one" class (e.g. a List) and a simple object reference from the "many" class. For example: public class Master { private List details; } public class Detail { private Master master; } I want to map this onto the database with just a foreign key in the detail table, plus an index field to maintain the ordering. How can I do this? I seemed to be able to manage this with 0.9.4, but with 0.9.5 I'm not so sure. If I do something like this: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping SYSTEM "hibernate-mapping.dtd"> <hibernate-mapping> <class name="Master"> <id name="oid"> <generator class="hilo.long"/> </id> <list role="details"> <key column="master_oid"/> <index column="master_seq"/> <one-to-many class="Detail"/> </list> </class> <class name="Detail"> <id name="oid"> <generator class="hilo.long"/> </id> <many-to-one name="master"/> </class> </hibernate-mapping> ...then I end up with two foreign key references in the DETAIL table: 'master_oid' and 'master'. If I try to force the many-to-one to use the same column the schema generator tries to build a table with two columns of the same name: <many-to-one name="master" column="master_oid"/> Is this possible? How does the code work internally? Does it have the concept of "two ends of the same association", or does it just treat this is two totally independant associations. PaulS :( |