I am facing a really weird problem with removing a element from a hashset , with the element coming from the hashset itself
This is the results i am getting:
-------------------------------------
before user.getSimpleMessageServiceMessages().size():1
smsMsg1:SimpleMessageServiceMessage@1
smsMsg1.getId():1
user.getSimpleMessageServiceMessages().contains(smsMsg1):false
user.getSimpleMessageServiceMessages().remove(smsMsg1):false
after user.getSimpleMessageServiceMessages().size():1
-------------------------------------
smsMsg1 is taken out from user.getSimpleMessageServiceMessages().toArray()[0]
the same object is used in the call to :user.getSimpleMessageServiceMessages().remove(smsMsg1) and also
user.getSimpleMessageServiceMessages().contains(smsMsg1), both of which gave me FALSE!!!
The underlying implementation of the set is java.util.Set
I dont have this problem with other normal parent to child r/s in hibernate. The only difference is that i am using discriminator classes as the child which in this case is SimpleMessageServiceMessage
The hibernate file goes as below:
<?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="MobileMessage" table="MOBILE_MESSAGE">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="msg_type" type="string"/>
<property name="senderMobileNumber" column="sender_mobile_num" not-null="true" type="string" />
<property name="receipientMobileNumber" column="receipient_mobile_num" not-null="true" type="string"/>
<many-to-one name="user" class="reynolds.sms.hibernate.User" column="user_id" not-null="true"/>
<subclass name="SimpleMessageServiceMessage" discriminator-value="SMS">
<property name="message" column="text_msg" type="string"/>
</subclass>
<subclass name="MultimediaMessage" discriminator-value="MMS">
<property name="message" column="text_msg" type="string"/>
<property name="picture" column="picture" type="string"/>
</subclass>
</class>
</hibernate-mapping>
The parent side of the relationship in the User.hbm.xml file is :
<set name="simpleMessageServiceMessages" cascade="all" lazy="true" inverse="true">
<key column="user_id"/>
<one-to-many class="SimpleMessageServiceMessage"/>
</set>
obviously, since i cant seem to delete that particular object from User, and when i try to sess.delete(smsMsg1); i get a hibernate error.
The only way i can remove smsMsg1 is to call user.getSimpleMessageServiceMessage().clear(). Thats the only way. Has anyone faced such a frustrating and illogical code problem?
|