-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one-to-many relationship - need help
PostPosted: Mon Aug 28, 2006 2:10 am 
Newbie

Joined: Tue Aug 22, 2006 5:26 am
Posts: 10
Location: Pakistan
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.xml

Code:
<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

_________________
Tahir


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.