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
|