-->
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.  [ 5 posts ] 
Author Message
 Post subject: One-to-many and another one-to-many
PostPosted: Fri Feb 03, 2006 7:43 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hi,
I have 4 tables called TEMPLATE, TEMPLATE_ELEMENT and ELEMENT_PARAMETER and PARAMETER.

I have declared an one-to-many Set "templateElements" on the "TEMPLATE" table and another one-to-many Set "elelmentParams" on the "TEMPLATE_ELEMENT" table.

Loading a collection of TEMPLATE it is working fine, updating is working fine, saving is working fine.

But when it comes to deleting the template Object, it throws me the following error,


Hibernate: delete from element_param where ELEMENT_ID=? and PARAMETER_ID=?
Hibernate: delete from template_element where ELEMENT_ID=?
Hibernate: delete from template1 where TEMPLATE_ID=?
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [delete from template1 where TEMPLATE_ID=?]; Cannot delete or update a parent row: a foreign key constraint fails; nested exception is java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails
java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:642)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)


Can somebody tell me why??

If needed I can even post my hbm files.

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 8:15 am 
Newbie

Joined: Wed May 25, 2005 10:53 pm
Posts: 13
Hi.

Just check if you have mentioned the foll. attribute for your one-to-many mapping for both the associations:

cascade="all-delete-orphan"

It will help if you can post ur hbm files


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 12:51 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hey,
That wouldn't work for me. :-)

Sorry for the late reply. Was not in town.


Here are my hbm files.

Template1:


Code:
<class name="Template1" table="template1">
        <id name="templateId" column="TEMPLATE_ID" type="java.lang.Integer" >
            <generator class="native"/>
        </id>

        <property name="templateName" column="TEMPLATE_NAME" type="java.lang.String"  not-null="true" />
        <property name="lastUpdateTime" column="LAST_UPDATE_TIME" type="java.util.Date" />
        <property name="lastUpdateUser" column="LAST_UPDATE_USER" type="java.lang.String"  not-null="true" />


        <list name="templateElements" table="template_element" cascade="save-update,delete" inverse="true">
            <key column="TEMPLATE_ID" not-null="true"/>
            <index column="SEQUENCE" type="java.lang.Integer" />
            <one-to-many class="TemplateElement"/>
        </list>

<!-- I have also used set here. Still doesn't work. :-( -->

    </class>






Element Param:

Code:
    <class name="ElementParam" table="element_param">
        <composite-id name="id" class="ElementParamKey">
          <key-many-to-one name="templateElement" column="ELEMENT_ID" class="TemplateElement" />
          <key-many-to-one name="parameter" column="PARAMETER_ID" class="Parameter" lazy="false"/>
        </composite-id>

        <property name="lastUpdateTime" column="LAST_UPDATE_TIME" type="java.util.Date" />
        <property name="lastUpdateUser" column="LAST_UPDATE_USER" type="java.lang.String" not-null="true" />
        <property name="sequence" column="SEQUENCE" type="java.lang.Integer" />



    </class>



Template Element:

Code:
<class name="TemplateElement" table="template_element">
        <id name="elementId" column="ELEMENT_ID" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="elementType" column="ELEMENT_TYPE" type="java.lang.String"  not-null="true" />
        <property name="elementName" column="ELEMENT_NAME" type="java.lang.String"  not-null="true" />
        <property name="lastUpdateTime" column="LAST_UPDATE_TIME" type="java.util.Date" />
        <property name="lastUpdateUser" column="LAST_UPDATE_USER" type="java.lang.String"  not-null="true" />

        <many-to-one name="templateElement" column="PARENT_ID" class="TemplateElement"  cascade="save-update"/>

        <many-to-one name="template1" column="TEMPLATE_ID" class="Template1" not-null="true"/>

    <set name="childElementParams" table="element_param" cascade="save-update,persist,merge,delete" inverse="true">
           <key column="ELEMENT_ID" not-null="true"/>
           <one-to-many class="ElementParam" />
    </set>

        <!--<set name="childTemplateElements" table="element_param" cascade="save-update,delete" inverse="false">
            <key column="PARENT_ID"/>
            <one-to-many class="TemplateElement"/>
        </set> -->




    </class>



Parameter:

Code:
<class name="Parameter" table="parameter">
        <id name="parameterId" column="PARAMETER_ID" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="parameterName" column="PARAMETER_NAME" type="java.lang.String"  not-null="true" />
        <property name="parameterDescription" column="PARAMETER_DESCRIPTION" type="java.lang.String" />
        <property name="parameterIndex" column="PARAMETER_INDEX" type="java.lang.String" />
        <property name="clinicalType" column="CLINICAL_TYPE" type="java.lang.String" />
        <property name="dataType" column="DATA_TYPE" type="java.lang.String" />
        <property name="transferType" column="TRANSFER_TYPE" type="java.lang.String" />
        <property name="unit" column="UNIT" type="java.lang.String" />
        <property name="max" column="MAX" type="java.lang.Integer" />
        <property name="min" column="MIN" type="java.lang.Integer" />
        <property name="autoValidation" column="AUTO_VALIDATION" type="java.lang.Short" />
        <property name="autoCopy" column="AUTO_COPY" type="java.lang.Short" />
        <property name="lastUpdateTime" column="LAST_UPDATE_TIME" type="java.util.Date" />
        <property name="lastUpdateUser" column="LAST_UPDATE_USER" type="java.lang.String" />

        <set name="parents" table="CATEGORY_PARAMETER">
            <key column="PARAMETER_ID" />
            <many-to-many column="CATEGORY_ID" class="Category"/>
        </set>

        <!--<use it when you need the parent TemplateElements using this Parameter>-->
       
        <!--<set name="parentElements" table="element_param" cascade="save-update,persist">-->
           <!--<key column="PARAMETER_ID" not-null="true"/>-->
           <!--<many-to-many column="ELEMENT_ID" class="TemplateElement"/>-->
        <!--</set>-->

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 1:39 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Guys thanks a lot.
I did what i needed. i got the deletiong thing working.

:-)

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 5:06 pm 
Newbie

Joined: Sat Sep 10, 2005 3:05 am
Posts: 6
Location: Paris
Hello,

I have the same problem.

Could you explain what is the thing you have done.
Or any clue to resolve this kind of problem ?

I will help me save some time searching... ;-)

Thank you,

_________________
Antoine Herzog.
JBoss Portal and GateIn (JSR-286), JSF, Richfaces, J2EE, Drools, BRMS.
http://www.sysemo.com/Sysemo-expertise- ... portal.php


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