Need help with Hibernate one-to-many relationship?
I have two tables,
UserAccount (PK userID, FK businessID)
business (PK businessID)
businessID is forign key in UserAccount (one business has many users)
I m using Eclipse 3.1 and genrate code by reveng file
it generated two hbm files (UserAccount.hbm.xml and business.hbm.xml)
My question is
how i programatically put data in thses two tables (offcourse from a single form), How I code a method which will insert data in these two tables how UserAccountHome and BusinessHome will help?
Whn working with relations do it generate extra tables for relations, if yes then how they used?
Mapping documents: UserAccount.hbm.xml
Code:
<hibernate-mapping>
<class name="tyn.cm.hibernate.UserAccount" table="userAccount" schema="dbo" catalog="YellowNumber">
<id name="userId" type="long">
<column name="userID" />
<generator class="assigned" />
</id>
[b]<many-to-one name="business" class="tyn.cm.hibernate.Business" fetch="select">
<column name="businessID" length="36" />
</many-to-one>
[/b] <property name="userName" type="string">
<column name="userName" length="36" not-null="true" unique="true" />
</property>
<property name="password" type="string">
<column name="password" length="50" not-null="true" />
</property>
<property name="firstName" type="string">
<column name="firstName" length="50" not-null="true" />
</property>
<property name="lastName" type="string">
<column name="lastName" length="50" not-null="true" />
</property>
</class>
</hibernate-mapping>
Mapping documents: Business.hbm.xmlCode:
<hibernate-mapping>
<class name="tyn.cm.hibernate.Business" table="business" schema="dbo" catalog="YellowNumber">
[b] <id name="businessId" type="string">
<column name="businessID" length="36" />
<generator class="assigned" />
</id>[/b]
<property name="businessName" type="string">
<column name="businessName" length="50" />
</property>
<property name="scheduleId" type="string">
<column name="scheduleID" length="36" />
</property>
<property name="allowanceId" type="string">
<column name="allowanceID" length="36" />
</property>
<property name="phone" type="string">
<column name="phone" length="20" />
</property>
<property name="timeZone" type="string">
<column name="timeZone" length="10" />
</property>
<property name="status" type="java.lang.Byte">
<column name="status" />
</property>
<property name="promotions" type="string">
<column name="promotions" length="20" />
</property>
<property name="promoStartDate" type="timestamp">
<column name="promoStartDate" length="23" />
</property>
<property name="promoEndDate" type="timestamp">
<column name="promoEndDate" length="23" />
</property>
<property name="logo" type="binary">
<column name="logo" />
</property>
<property name="modifyDate" type="timestamp">
<column name="modifyDate" length="23" />
</property>
<property name="createDate" type="timestamp">
<column name="createDate" length="23" />
</property>
[b]<set name="userAccounts" inverse="true">
<key>
<column name="businessID" length="36" />
</key>
<one-to-many class="tyn.cm.hibernate.UserAccount" />
</set>[/b]
</class>
</hibernate-mapping>
Kindly suggest me how I start with relations...
Looking for ur valueable help
rgd