-->
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: null values in records which needs to be deleted
PostPosted: Fri Sep 08, 2006 2:46 am 
Beginner
Beginner

Joined: Mon Mar 14, 2005 9:07 am
Posts: 27
Hi all,

When I do the below what is does is that it creates a new row in the PHONE_NUMBER table with the new values of the new phone number object which is right but instead of deleting the old values of phone number (because I have used instance.getPhoneNumbers().clear()) it nulllifies the values of the old record.

This is leading to creation of large number of null rows in the Phone_Number table which should have ideally been deleted. Can anyone explain me why this is happening

Hibernate version: Hibernate 3.0.5

Mapping documents:
<class name="MyClass"
table="MY_CLASS">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="requestDate" type="timestamp" column="REQUEST_DATE"/>
<property name="requester" column="REQUESTER" type="java.lang.String"/>
<set name="phoneNumbers" cascade="all" access="field" lazy="false">
<key column="MYCLASS_ID" not-null="false"/>
<one-to-many class="PhoneNumber"/>
</set>
</class>

<class name="PhoneNumber">
table="PHONE_NUMBER">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="native">
</generator>
</id>
<property name="areaCode" type="java.lang.String" column="AREA_CODE"/>
<property name="number" type="java.lang.String" column="NUMBER"/>
<property name="extension" type="java.lang.String" column="EXTENSION"/>
<property name="type" type="int" column="PHONE_TYPE_ID"/>
</class>


Code between sessionFactory.openSession() and session.close():

PhoneNumber phoneNumber = new PhoneNumber("610", "964 5235", "");

MyClass instance = (MyClass) s.get(MyClass.class, id);
instance.getPhoneNumbers().clear();//since phone number array is a Set
[b]instance.setPhoneNumbers(new HashSet(phoneNumber));
HibernateUtil.currentSession().saveOrUpdate(instance);




Name and version of the database you are using:SQL Server 2000

In case anything is not clear please let me know.

Thanks for help,
Ashish Abrol


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.