-->
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.  [ 7 posts ] 
Author Message
 Post subject: child record is not inserted in one-to-many uni directional
PostPosted: Fri Aug 08, 2008 10:23 am 
Newbie

Joined: Fri Aug 08, 2008 7:29 am
Posts: 6
Location: hyderabad
We are using uni directional one -to-many relation .
We are facing one problem .

Please help me out in resolving this.

I have two tables snp_issuer(parent),snp_note(child)

CREATE TABLE SNP_ISSUER (
ISSUERID NUMBER (10) NOT NULL,
ISSUER_NAME VARCHAR2 (30) NOT NULL,
CONSTRAINT SNP_ISSUER_PK
PRIMARY KEY ( ISSUERID ) ) ;

CREATE TABLE SNP_NOTE (
NOTE_REF_ID NUMBER (10) NOT NULL,
ISSUERID NUMBER (10),
PRIMARY KEY ( NOTE_REF_ID ) ) ;

When iam saving parent record is been inserted into parent table, but child records are not getting inserted.

Note n1 = new Note();
Note n2 = new Note();
n1.setMininvest("100");
n1.setNotename("sample note");
n1.setMininvest("200");
n1.setNotename("sample note2");
issuer.getNotelst().add(n1);
issuer.getNotelst().add(n2);
getHibernateTemplate().save(issuer);

hbm files declaration is as below

Parent
<hibernate-mapping>

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

<meta attribute="class-description">

</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>

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

</class>
</hibernate-mapping>

child

<!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="issuerId" type="int" column ="ISSUERID">
</property>
</class>
</hibernate-mapping>

We are using spring hibernatedao support
and oracle database

Please advise us on this problem


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 10:53 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I guess you don't need to specify the property for ISSUERID column in mapping for Notes class. Removing that property from mapping and see if it works.

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 12:05 pm 
Newbie

Joined: Fri Aug 08, 2008 7:29 am
Posts: 6
Location: hyderabad
thanks for ur suggestion
But i have tried that option too.
It did't worked


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 4:38 pm 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Post your mapping and java files, I try to figure out the issue.

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 12:58 am 
Newbie

Joined: Fri Aug 08, 2008 7:29 am
Posts: 6
Location: hyderabad
hbm files
[code]<?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>
[/code]
[code]<?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>
[/code]
Implementation class
[code]public class IssuerDAOImpl extends HibernateDaoSupport {

public boolean insert(Issuer issuer) throws DataAccessException {


Note n1 = new Note();
Note n2 = new Note();
n1.setMininvest("100");
n1.setNotename("sample note");
n1.setMininvest("200");
n1.setNotename("sample note2");
issuer.getNotelst().add(n1);
issuer.getNotelst().add(n2);
getHibernateTemplate().save(issuer);

return true;
}

}[/code]
database scripts
[code]CREATE TABLE SNP_NOTE (
NOTE_NAME VARCHAR2 (100),
NOTE_REF_ID NUMBER (10) NOT NULL,
MIN_INVESTMENT VARCHAR2 (50),
ISSUERID NUMBER (10),
PRIMARY KEY ( NOTE_REF_ID ) ) ;

ALTER TABLE SNP_NOTE ADD
FOREIGN KEY (ISSUERID)
REFERENCES MIFTFLOW.SNP_ISSUER (ISSUERID) ;[/code]
[code]CREATE TABLE SNP_ISSUER (
ISSUERID NUMBER (10) NOT NULL,
ISSUER_NAME VARCHAR2 (30) NOT NULL,
ISSUER_ADDRESS VARCHAR2 (100),
RECIPIENT_EMAIL VARCHAR2 (30),
RVP_SETTLEMENT VARCHAR2 (30),
MARKET_REGIONS VARCHAR2 (30),
INITIATED_BY VARCHAR2 (30),
INITIATE_DATE DATE,
MODIFIED_BY VARCHAR2 (30),
MODIFIED_DATE DATE,
COMMAND VARCHAR2 (30),
DISTRIBUTION_AGREEMENTS VARCHAR2 (30),
STATUS VARCHAR2 (30),
CONSTRAINT SNP_ISSUER_PK
PRIMARY KEY ( ISSUERID ) ) ; [/code]

Using hibernate 2.0 version
Spring 1.0

Show sql
Hibernate: insert into SNP_ISSUER (ISSUER_NAME, ISSUER_ADDRESS, RECIPIENT_EMAIL, RVP_SETTLEMENT, MARKET_REGIONS, INITIATED_BY, INITIATE_DATE, COMMAND, STATUS, ISSUERID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update SNP_NOTE set NOTE_NAME=?, MIN_INVESTMENT=? where NOTE_REF_ID=?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 12:59 am 
Newbie

Joined: Fri Aug 08, 2008 7:29 am
Posts: 6
Location: hyderabad
Plz find abouve the code fiels
I don't know why show sql is showing update statement like this

Hibernate: insert into SNP_ISSUER (ISSUER_NAME, ISSUER_ADDRESS, RECIPIENT_EMAIL, RVP_SETTLEMENT, MARKET_REGIONS, INITIATED_BY, INITIATE_DATE, COMMAND, STATUS, ISSUERID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update SNP_NOTE set NOTE_NAME=?, MIN_INVESTMENT=? where NOTE_REF_ID=?


Top
 Profile  
 
 Post subject: Re: child record is not inserted in one-to-many uni directional
PostPosted: Thu Jun 03, 2010 2:51 am 
Newbie

Joined: Thu Jun 03, 2010 2:29 am
Posts: 1
I will read time to time that


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.