i'm trying to map a relationship between two class which have one-to-one relationship. After looking up on the internet it seems like people prefer to map it using many-to-one.
for example have have a class Order and a class Bill. Bill holds a FK to the invoice.
Here are my mapping for Bill
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated Mar 21, 2016 10:46:20 PM by Hibernate Tools 3.5.0.Final --> <hibernate-mapping> <class name="domain.Bill" table="BILL"> <id name="id" type="int"> <column name="ID" /> <generator class="native" /> </id> <many-to-one name="order" class="domain.Order" column="ORDER_ID" unique="true" not-null="true"/> </class> </hibernate-mapping>
As you can see above, in my mapping of Bill I can specified the column of Fk to the Order, but what should put in my mapping for Order since it does not have a Fk to Bill?
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated Mar 21, 2016 10:46:20 PM by Hibernate Tools 3.5.0.Final --> <hibernate-mapping> <class name="domain.Order" table="ORDER"> <id name="id" type="int"> <column name="ID" /> <generator class="native" /> </id> <many-to-one name="bill" class="domain.Bill" ???? fetch="select"/> </class> </hibernate-mapping>
No comments:
Post a Comment