-->
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.  [ 4 posts ] 
Author Message
 Post subject: Delete problem
PostPosted: Fri Aug 12, 2005 3:01 pm 
Newbie

Joined: Tue Jul 19, 2005 1:28 pm
Posts: 17
Hi,
I am having a problem with delete. These are my mapping files

Facility.hbm.xml

<hibernate-mapping>
<class name="org.eplan.tierII.dataObjects.Facility" table="facility">
<id name="facilityid" column="facilityId">
<generator class="increment" />
</id>
<property name="facilityname" column="facilityname" />
<property name="department" column="department" />
<property name="filingyear" column="filingYear" />
<property name="latitude" />
<property name="longitude" />
<property name="methodOfDetermination" column="methodofdetermination"/>
<property name="numberofemployees" />
<property name="locationdescription" />
<property name="streetAddressId" column="streetaddressid" />
<property name="mailingAddressId" column="mailaddressid" />
<property name="corporateEmail" column="corporateemail" />
<property name="submittedBy" column="submittedby" />
<property name="submittedDate" type="date" column="submitteddate" />


<set name="stateFields" table="facilitystatefields" cascade="all,delete-orphan" >
<key>
<column name="facilityid"/>
</key>
<one-to-many class="org.eplan.tierII.dataObjects.Facilitystatefields" />
</set>

<set name="facilityLocations" table="facilitylocations" cascade="all">
<key>
<column name="facilityid" not-null="false"/>
</key>
<one-to-many class="org.eplan.tierII.dataObjects.FacilityLocations" />
</set>

<set name="facilityContacts" table="facilitycontacts" cascade="all">
<key>
<column name="facilityid" scale="11" precision="0" not-null="false" />
</key>
<one-to-many class="org.eplan.tierII.dataObjects.Facilitycontacts" />
</set>

<set name="facilityChemicals" table="facilitychemicals" cascade="all">
<key>
<column name="facilityid" />
</key>
<one-to-many class="org.eplan.tierII.dataObjects.FacilityChemicals" />
</set>

</class>
</hibernate-mapping>

Facilitystatefields.hbm.xml
<hibernate-mapping>
<class name="org.eplan.tierII.dataObjects.Facilitystatefields" table="facilitystatefields" >
<composite-id name="id" class="org.eplan.tierII.dataObjects.FacilitystatefieldsId">
<key-many-to-one name="Statefields" class="org.eplan.tierII.dataObjects.StateFields">
<column name="fieldid" scale="10" precision="0" not-null="true" />
</key-many-to-one>
<key-many-to-one name="Facility" class="org.eplan.tierII.dataObjects.Facility" >
<column name="facilityid" scale="11" precision="0" not-null="true"/>
</key-many-to-one>
</composite-id>

<property name="Fieldvalue" type="java.lang.String">
<column name="fieldvalue" scale="30" precision="0" not-null="true" sql-type="varchar" />
</property>

</class>
</hibernate-mapping>


StateFields.hbm.xml
<hibernate-mapping>

<class name="org.eplan.tierII.dataObjects.StateFields" table="statefields">

<id name="fieldId" column="fieldid">
<generator class="increment"/>
</id>
<property name="filingYear" column="filingYear" />
<property name="state" />
<property name="country" />
<property name="fieldName" column="fieldname"/>
<property name="fieldType" column="fieldtype"/>
<property name="fieldLabel" column="fieldlabel"/>
</class>

</hibernate-mapping>

I do not want any Set of Facilities in StateFields. So I am not unsing any set with inverse in StateFields.

I am having no problem in doing Facility.getStateFields().add(new Facilitystatefields(....));

But when I want to delete from that set using Facility.getStateFields().clear();

I see the Hibernate debug statements as : update facilitystatefileds set facilityid = null where facilityid = ?
and this causes a foreign key constraint voilation since it is being set to null.

Even if I do an explicit delete of each Facilitystatefields object from the set, I am not able to do so and getting the same error message as above.


What am I doing wrong? are my associations wrong?. Please help.

Thanks
Phani


Top
 Profile  
 
 Post subject: Re: Delete problem
PostPosted: Fri Aug 12, 2005 3:08 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Try adding inverse="true" to the <set> mapping.


Code:
<set name="stateFields" table="facilitystatefields" inverse="true" cascade="all,delete-orphan" >
  <key>
    <column name="facilityid"/>            
  </key>         
  <one-to-many class="org.eplan.tierII.dataObjects.Facilitystatefields" />      </set>

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: It works!!!!!
PostPosted: Fri Aug 12, 2005 3:55 pm 
Newbie

Joined: Tue Jul 19, 2005 1:28 pm
Posts: 17
You are wonderful!!!


It really works. Thanks a lot. I have been scratching my head on this for two days now.

If possible can you explain the effect of having inverse="true".

Thanks once again.

regards
Phani


Top
 Profile  
 
 Post subject: Re: It works!!!!!
PostPosted: Fri Aug 12, 2005 4:07 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
phanivas wrote:
You are wonderful!!!


It really works. Thanks a lot. I have been scratching my head on this for two days now.

If possible can you explain the effect of having inverse="true".

Thanks once again.

regards
Phani


Hopefully one of the Hibernate guys will correct me if I'm wrong but I think it tells hibernate to look at the other end of the association to determine the relationship in Java.

In your case, it says "Facilitystatefields doesn't control the relationship, Facility does."

Since you cleared the set and essentially deleted the relationship, hibernate should delete the Facilitystatefields.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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