-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Foreign Key Mapping
PostPosted: Fri May 25, 2007 2:39 am 
Newbie

Joined: Fri May 25, 2007 2:27 am
Posts: 2
Hi,

I'm new to Hibernate, I'm having table in Oracle with parent and child relationship.

PartRequest(Parent Table) and PartRequestInformation(Child Table). PartReqId is the primary key in the PR table and foreign key in PRI table.

In the PR table i'm generating the partrequestid through my customized class, it's working fine. But in PRI table, i need to refer the partrequestid which is generated already. How do I do that, whild i'm saving it, i need to explicitly push the partrequest object into the partrequestinformation domain object, then in need to save the partrequestinformation object one more time.

I need as this, once I generate the data into the partrequest domain object, it should take care about generating the partreqid and push that id into partreqinformation and save the whiole partrequest object in one save.



Code for Reference:
--------------------------------------------------------
PartRequest.hbm.xml
-------------------------
<class name="com.tms.t3.prs.domain.PartRequest" table="PART_REQUEST">
<id name="partReqId" type="big_decimal">
<column name="PART_REQ_ID" precision="22" scale="0" />
<generator class="com.tms.t3.prs.hibernate.PrsSequenceGenerator">
<param name="CURRENT_CNT">CURRENT_CNT</param>
<param name="TABLE">db_num_seq</param>
<param name="SEQUENCE">db_num_seq</param>
<param name="TABLE_TYPE">PART_REQUEST</param>
</generator>
</id>

<set name="partRequestInformations" table="part_request_information" inverse="true" cascade="save-update">
<key>
<column name="PART_REQ_ID" precision="22" scale="0" not-null="true" property-ref="PART_REQ_ID" />
</key>
<one-to-many class="com.tms.t3.prs.domain.PartRequestInformation" />
</set>

</class>
</hibernate-mapping>

----------------------------------------------------------------------------------
PartRequestInformation.hml.xml
---------------------------------------
<hibernate-mapping>
<class name="com.tms.t3.prs.domain.PartRequestInformation" table="PART_REQUEST_INFORMATION">
<many-to-one name="partRequest" class="com.tms.t3.prs.domain.PartRequest" fetch="select" cascade="save-update">
<column name="PART_REQ_ID" precision="22" scale="0" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>

Note: Can we refer the partreqid from partrequest hml file directly through
<property-ref>

Thanks
Muralidharan.K


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 5:01 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi


<set name="partRequestInformations" table="part_request_information" inverse="true" cascade="save-update">


set it to false

<many-to-one name="partRequest" class="com.tms.t3.prs.domain.PartRequest" fetch="select" cascade="save-update">

remove this


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 8:28 am 
Newbie

Joined: Fri May 25, 2007 2:27 am
Posts: 2
Hi,

This is not solving the issue.


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

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.