-->
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: unable to insert data into child table in one-to-many
PostPosted: Mon Aug 11, 2008 6:43 am 
Newbie

Joined: Fri Aug 08, 2008 7:29 am
Posts: 6
Location: hyderabad
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:2.0[/b]

[b]Mapping documents:

[b]Parent[/b]
<?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]

[b]child[/b]
<?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>


[b]Code between sessionFactory.openSession() and session.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;
}

}[/b]

[b]Full stack trace of any exception that occurs:no exception[/b]

[b]Name and version of the database you are using:oracle 10.2.1[/b]

[b]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=?[/b]

[b]Debug level Hibernate log excerpt:[/b]


We are trying to insert record into child table in one-to many uni directional relation.
Parent record is being getting inserted . problem with the child record insertion.

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.

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 7:27 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think you need to remove the inverse="true" attribute from the <set name="notelst" ...> mapping. The inverse="true" setting causes Hibernate to ignore changes (additions and removals) to the set. That is why you see no insertion SQL statement.

Alternatively, you could make the association bi-directional by including a <many-to-one> mapping in the mapping for the Note object. For more information about the latter option, the following example from the Hibernate documentation is recommended: http://www.hibernate.org/hib_docs/v3/re ... child.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 8:17 am 
Newbie

Joined: Fri Aug 08, 2008 7:29 am
Posts: 6
Location: hyderabad
Thanks for your reply.
I tried that but its not working.Still the same problem

Even Show sql also shows the same

Hibernate: update 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=?

Where insert statement to child is missing.

Plz advise


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.