aspose file tools*
The moose likes Object Relational Mapping and the fly likes problem with one-to-many child insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "problem with one-to-many child insertion" Watch "problem with one-to-many child insertion" New topic
Author

problem with one-to-many child insertion

anupama guntupalli
Greenhorn

Joined: Aug 11, 2008
Posts: 1
Hi

I was trying to insert child record with one to many uni directional relation.
But parent record is beinf inserted properly.but problem with the child insertion.



I have the below table structure


and parent hbm ,child hbm files


Parent
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.citigroup.snp.models.Issuer" table="SNP_ISSUER">

<meta attribute="class-description">
Represents a singleemployee info in the example database.
@author Naga Jyothi. (with help from Hibernate)
</meta>
<id name="issuerId" column="ISSUERID" type="int">
<generator class="increment" />
</id>

<property name="issuerName" type="string" column="ISSUER_NAME">

</property>

<property name="iaddress" type="string" column ="ISSUER_ADDRESS">

</property>

<property name="receipientEmail" type="string" column ="RECIPIENT_EMAIL">

</property>

<property name="rvpSettlement" type="string" column ="RVP_SETTLEMENT">

</property>

<property name="mktRegions" type="string" column ="MARKET_REGIONS">

</property>
<property name="initBy" type="string" column ="INITIATED_BY">

</property>

<property name="initDate" type="date" column ="INITIATE_DATE">

</property>


<property name="command" type="string" column ="COMMAND">

</property>


<property name="status" type="string" column ="STATUS">

</property>

<set
name="notelst"
inverse="true"
table="SNP_NOTE"
cascade="all"
lazy="false" >
<key column="ISSUERID" />
<one-to-many
class="com.citigroup.snp.models.Note"
/>
</set>

</class>
</hibernate-mapping>
[/b]

child
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.citigroup.snp.models.Note" table="SNP_NOTE">
<id name="noteid" column="NOTE_REF_ID" type="int">
<generator class="increment" />
</id>

<property name="notename" type="string" column ="NOTE_NAME">

</property>

<property name="mininvest" type="string" column ="MIN_INVESTMENT">

</property>

</class>
</hibernate-mapping>

and the code between session open and close.
public class IssuerDAOImpl extends HibernateDaoSupport {

public boolean insert() throws DataAccessException {

Issuer issuer =new Issuer();
issuer.setCommand("dfgdfg");
issuer.setIssuerName("dfgdfgdf");
issuer.setInitBy("anu");
Note n1 = new Note();
Note n2 = new Note();
n1.setMininvest("100");
n1.setNotename("sample note");
n2.setMininvest("200");
n2.setNotename("sample note2");
issuer.getNotelst().add(n1);

getHibernateTemplate().saveOrUpdate(issuer);

return true;
}

showsql output
The generated SQL (show_sql=true):
Hibernate: insert SNP_ISSUER set ISSUER_NAME=?, ISSUER_ADDRESS=?, RECIPIENT_EMAIL=?, RVP_SETTLEMENT=?, MARKET_REGIONS=?, INITIATED_BY=?, INITIATE_DATE=?, COMMAND=?, STATUS=? where ISSUERID=?

Hibernate: update SNP_NOTE set NOTE_NAME=?, MIN_INVESTMENT=? where NOTE_REF_ID=?

Even i can't understand in show sql there is no insert statement to the child tabla(i.e SNP_NOTE)

Please advise me on where iam going wrong.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Can you repost your mappings and code into CODE tags. There is a button under Add Reply that says "CODE". It will add the code tags and if you paste your xml and your code within those tags the indentation and formatting will remain to make it easier for us to read.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with one-to-many child insertion