-->
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.  [ 1 post ] 
Author Message
 Post subject: unable to save record using parent child relationship
PostPosted: Mon Jul 21, 2008 7:40 am 
Newbie

Joined: Mon Jul 21, 2008 7:13 am
Posts: 1
Hi
I am developing an e-commerce site.My requirement is that a person can have multiple address.Now when i am saving record for a person who has multiple address then i am getting these error

Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)

My hbm file is
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping >
<class name="infogain.uniDirectional.oneToMany.PersonOneToMany" table="Person_one_to_many">
<id name="personId" type="java.lang.String" column="person_id"></id>
<property name="personName" column="person_name" type="string"/>
<set name="addressOneToMany">
<key column="person_id" not-null="true" />
<one-to-many class="infogain.uniDirectional.oneToMany.AddressOneToMany"/>
</set>
</class>
<class name="infogain.uniDirectional.oneToMany.AddressOneToMany" lazy="true" table="Address_one_to_many" >
<id name="addressId" type="java.lang.String"
column="address_id"></id>
<property name="houseNo" type="java.lang.String" column="house_no"/>
<property name="street" type="java.lang.String" column="street"/>
</class>
</hibernate-mapping>


My POJO's are

public class PersonOneToMany {

private String personId;
private String personName;
private Set addressOneToMany = new HashSet();
//private AddressOneToMany address;



/*public AddressOneToMany getAddress() {
return address;
}
public void setAddress(AddressOneToMany address) {
this.address = address;
}*/
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
public String getPersonName() {
return personName;
}
public void setPersonName(String personName) {
this.personName = personName;
}
public Set getAddressOneToMany() {
return addressOneToMany;
}
public void setAddressOneToMany(Set addressOneToMany) {
this.addressOneToMany = addressOneToMany;
}

public void addAddressOneToMany(AddressOneToMany addresses){
addresses.setPersonOneToMany(this);
addressOneToMany.add(addresses);


}

}


ANOTHER CLASS AddressOneToMany

public class AddressOneToMany {

private String addressId;
private String houseNo;
private String street;
private PersonOneToMany personOneToMany;


public String getAddressId() {
return addressId;
}
public void setAddressId(String addressId) {
this.addressId = addressId;
}
public String getHouseNo() {
return houseNo;
}
public void setHouseNo(String houseNo) {
this.houseNo = houseNo;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public PersonOneToMany getPersonOneToMany() {
return personOneToMany;
}
public void setPersonOneToMany(PersonOneToMany personOneToMany) {
this.personOneToMany = personOneToMany;
}



This is my clien call method------------


public PersonOneToMany getDataFromUniDirectionOneToManyAssociation(){

PersonOneToMany person = new PersonOneToMany();

Session session=null;

try{
session = (Session)HibernateSessionFactory.getSession();

PersonOneToMany tempPerson = new PersonOneToMany();
System.out.println("\for parent child relationship started");
tempPerson.setPersonId("ra111");
tempPerson.setPersonName("rajmishra");
AddressOneToMany addTemp = new AddressOneToMany();
addTemp.setAddressId("AD1");
addTemp.setHouseNo("hs1");
addTemp.setStreet("st1");
addTemp.setPersonOneToMany(tempPerson);
hs.add(addTemp);
addTemp.setAddressId("AX11");
addTemp.setHouseNo("hX1w");
addTemp.setStreet("stw1w");
addTemp.setPersonOneToMany(tempPerson);
hs.add(addTemp);
tempPerson.setAddressOneToMany(hs);
session.save(tempPerson);
System.out.println(" for parent child relationship ended");
}

}catch(Exception e){
e.printStackTrace();
}finally{
if(session.isOpen()){
session.flush();
session.close();
}
}


Now it give the above mentioned error.

Any help in this regard will highly appreciated.

Thanks in advace
Raj Kamal[/b]


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

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.