-->
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.  [ 7 posts ] 
Author Message
 Post subject: Cascade delete in hibernate
PostPosted: Mon Mar 13, 2006 9:58 pm 
Newbie

Joined: Mon Mar 13, 2006 9:46 pm
Posts: 7
I am trying to delete the records from the database. I get 'SQLcould not execute update query' error. What am i doing wrong. Any help is appreciated

public static final Timestamp TODAYS_RECORD_TIME =new Timestamp(System.currentTimeMillis());

String delSql = " delete from EcoCmdyDelete where lastUptdDt< :lastUpDt ";
Query delQry = session.createQuery(delSql);
delQry.setTime("lastUpDt", TODAYS_RECORD_TIME );
delQry.executeUpdate();

I am getting the
'org.hibernate.util.JDBCExceptionReporter] [ORA-02292: integrity constraint (ECO.ECO_HZMT_DTL_F1) violated - child record found' exception


theres are my mapping files

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.uprr.app.eco.persistenceDelete.EcoCmdyDelete" table="ECO_CMDY" schema="ECO">
<id name="stccCode" type="string">
<column name="STCC_CODE" length="7" />
<generator class="assigned" />
</id>
<property name="hzrdInd" type="string">
<column name="HZRD_IND" length="1" />
</property>
<property name="effDate" type="date">
<column name="EFF_DATE" length="7" />
</property>
<property name="cmdyAbrv" type="string">
<column name="CMDY_ABRV" length="6" />
</property>
<property name="intlHmzdCode" type="string">
<column name="INTL_HMZD_CODE" length="6" />
</property>
<property name="svcRqmtCode1" type="string">
<column name="SVC_RQMT_CODE_1" length="1" />
</property>
<property name="svcRqmtCode2" type="string">
<column name="SVC_RQMT_CODE_2" length="1" />
</property>
<property name="svcRqmtCode3" type="string">
<column name="SVC_RQMT_CODE_3" length="1" />
</property>
<property name="wgtTolrFctr" type="integer">
<column name="WGT_TOLR_FCTR" precision="1" scale="0" />
</property>
<property name="cmdyBaseNbr" type="short">
<column name="CMDY_BASE_NBR" precision="3" scale="0" />
</property>
<property name="unnaNbr" type="string">
<column name="UNNA_NBR" length="6" />
</property>
<property name="crtnDt" type="date">
<column name="CRTN_DT" length="7" not-null="true" />
</property>
<property name="crtnUserId" type="string">
<column name="CRTN_USER_ID" length="8" not-null="true" />
</property>
<property name="lastUptdDt" type="timestamp">
<column name="LAST_UPTD_DT" length="7" not-null="true" />
</property>
<property name="lastUptdUserId" type="string">
<column name="LAST_UPTD_USER_ID" length="8" not-null="true" />
</property>
<property name="cmdyDesc" type="string">
<column name="CMDY_DESC" length="720" />
</property>
<!-- <property name="prodClassStcc" type="string">
<column name="PROD_CLAS_STCC_CODE" length="7" />
</property> -->

<set name="ecoHzrdEmgyResps" cascade="delete" >
<key>
<column name="STCC_CODE" length="7" not-null="true" />
</key>
<one-to-many class="com.uprr.app.eco.persistenceDelete.EcoHzrdEmgyRespDelete" />
</set>

<set name="ecoCommodities" cascade="delete">
<key>
<column name="PROD_CLAS_STCC_CODE" length="7" />
</key>
<one-to-many class="com.uprr.app.eco.persistenceDelete.EcoCmdyDelete" />
</set>

<set name="ecoHzmtDtls" cascade="delete">
<key>
<column name="STCC_CODE" length="7" not-null="true" />
</key>
<one-to-many class="com.uprr.app.eco.persistenceDelete.EcoHzmtDtlDelete" />
</set>
<set name="ecoHzmtNameDescs" cascade="delete" >
<key>
<column name="STCC_CODE" length="7" not-null="true" />
</key>
<one-to-many class="com.uprr.app.eco.persistenceDelete.EcoHzmtNameDescDelete" />
</set>
</class>
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.uprr.app.eco.persistenceDelete.EcoHzrdEmgyRespDelete" table="ECO_HZRD_EMGY_RESP" schema="ECO">
<composite-id name="id" class="com.uprr.app.eco.persistenceDelete.EcoHzrdEmgyRespId">
<key-property name="stccCode" type="string">
<column name="STCC_CODE" length="7" />
</key-property>
<key-property name="lineNbr" type="byte">
<column name="LINE_NBR" precision="2" scale="0" />
</key-property>
</composite-id>
<many-to-one name="ecoCmdy" class="com.uprr.app.eco.persistenceDelete.EcoCmdyDelete" update="false" insert="false" fetch="select">
<column name="STCC_CODE" length="7" not-null="true" />
</many-to-one>
<property name="crtnDt" type="date">
<column name="CRTN_DT" length="7" not-null="true" />
</property>
<property name="crtnUserId" type="string">
<column name="CRTN_USER_ID" length="8" not-null="true" />
</property>
<property name="lastUptdDt" type="date">
<column name="LAST_UPTD_DT" length="7" not-null="true" />
</property>
<property name="lastUptdUserId" type="string">
<column name="LAST_UPTD_USER_ID" length="8" not-null="true" />
</property>
<property name="emgyRespText" type="string">
<column name="EMGY_RESP_TEXT" length="80" not-null="true" />
</property>
</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.uprr.app.eco.persistenceDelete.EcoHzmtDtlDelete" table="ECO_HZMT_DTL" schema="ECO">
<composite-id name="id" class="com.uprr.app.eco.persistenceDelete.EcoHzmtDtlId">
<key-property name="stccCode" type="string">
<column name="STCC_CODE" length="7" />
</key-property>
<key-property name="regAuthCode" type="string">
<column name="REG_AUTH_CODE" length="1" />
</key-property>
</composite-id>
<many-to-one name="ecoCmdy" class="com.uprr.app.eco.persistenceDelete.EcoCmdyDelete" update="false" insert="false" >
<column name="STCC_CODE" length="7" not-null="true" />
</many-to-one>
<property name="primInd" type="string">
<column name="PRIM_IND" length="1" />
</property>
<property name="hzrdZoneCode" type="string">
<column name="HZRD_ZONE_CODE" length="1" />
</property>
<property name="packGrpCode" type="string">
<column name="PACK_GRP_CODE" length="1" />
</property>
<property name="hzrdClasCode" type="string">
<column name="HZRD_CLAS_CODE" length="4" />
</property>
<property name="psnInd" type="string">
<column name="PSN_IND" length="1" />
</property>
<property name="subClasCode1" type="string">
<column name="SUB_CLAS_CODE_1" length="3" />
</property>
<property name="subClasCode2" type="string">
<column name="SUB_CLAS_CODE_2" length="3" />
</property>
<property name="subClasCode3" type="string">
<column name="SUB_CLAS_CODE_3" length="3" />
</property>
<property name="primPlrdNotnCode" type="string">
<column name="PRIM_PLRD_NOTN_CODE" length="2" />
</property>
<property name="scndPlrdNotnCode" type="string">
<column name="SCND_PLRD_NOTN_CODE" length="2" />
</property>
<property name="inmdInd" type="string">
<column name="INMD_IND" length="1" />
</property>
<property name="spclCmdyInd" type="string">
<column name="SPCL_CMDY_IND" length="1" />
</property>
<property name="rptlQtyInd" type="string">
<column name="RPTL_QTY_IND" length="1" />
</property>
<property name="emgyRespPlanInd" type="string">
<column name="EMGY_RESP_PLAN_IND" length="1" />
</property>
<property name="nosInd" type="string">
<column name="NOS_IND" length="1" />
</property>
<property name="marnPoluInd" type="string">
<column name="MARN_POLU_IND" length="1" />
</property>
<property name="plrdEndrCode" type="string">
<column name="PLRD_ENDR_CODE" length="2" />
</property>
<property name="crtnDt" type="date">
<column name="CRTN_DT" length="7" not-null="true" />
</property>
<property name="crtnUserId" type="string">
<column name="CRTN_USER_ID" length="8" not-null="true" />
</property>
<property name="lastUptdDt" type="date">
<column name="LAST_UPTD_DT" length="7" not-null="true" />
</property>
<property name="lastUptdUserId" type="string">
<column name="LAST_UPTD_USER_ID" length="8" not-null="true" />
</property>
</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.uprr.app.eco.persistenceDelete.EcoHzmtDescLineDelete" table="ECO_HZMT_DESC_LINE" schema="ECO">
<id name="nameDescId" type="long">
<column name="NAME_DESC_ID" precision="10" scale="0" />
<generator class="assigned" />
</id>
<property name="hzmtNameDesc" type="string">
<column name="HZMT_NAME_DESC" length="25" not-null="true" />
</property>
<property name="crtnDt" type="date">
<column name="CRTN_DT" length="7" not-null="true" />
</property>
<property name="crtnUserId" type="string">
<column name="CRTN_USER_ID" length="8" not-null="true" />
</property>
<set name="ecoHzmtNameDescs" inverse="true">
<key>
<column name="NAME_DESC_ID" precision="10" scale="0" not-null="true" />
</key>
<one-to-many class="com.uprr.app.eco.persistenceDelete.EcoHzmtNameDescDelete" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 10:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You're trying to delete a row that has other rows referring to it. The database won't let you do that. If you used session.delete() instead of that update query, hibernate would know what you're doing and would cascade the deletes for you. So you should either improve your delete statement to delete all dependent objects, or else load all the objects using hibernate then delete them.

When posting code, please use code tags.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 11:14 pm 
Newbie

Joined: Mon Mar 13, 2006 9:46 pm
Posts: 7
<code>

Code:
public  static void  deleteOldData()
    {
       
        Transaction tx=session.beginTransaction();
       
        try{     
           
           
           
            System.out.println("deleteOldData");
            String delSql = "from  EcoCmdyDelete c where  c.lastUptdDt< :lastUpDt ";             
            Query delQry = session.createQuery(delSql);
            delQry.setTime("lastUpDt", TODAYS_RECORD_TIME );         
            List qList =delQry.list();
            int count =0;
            if(qList!=null && qList.size()>0 )
            {
                Iterator i= qList.iterator();
              while(i.hasNext() && count<1)
              {
                  count++;
                  EcoCmdyDelete cmdy =(EcoCmdyDelete)i.next();                 
                 
                  Iterator htdt=cmdy.getEcoHzmtDtls().iterator();
                  if( htdt.hasNext())
                  {
                      session.delete(htdt.next());
                  }
                  Iterator htemr=cmdy.getEcoHzrdEmgyResps().iterator();
                  if(htemr.hasNext())
                  {
                      session.delete(htemr.next());
                  }
                  Iterator htdtNms=cmdy.getEcoHzmtNameDescs().iterator();
                  if( htdtNms.hasNext())
                  {
                      session.delete(htdtNms.next());
                  }
                  Iterator prdcls=cmdy.getEcoCommodities().iterator();
                  if( prdcls.hasNext())
                  {
                      session.delete(prdcls.next());
                  }
                 
                  session.delete( cmdy );
                 
              }
            }
           
           
//         
           
            tx.commit();
           
       
        }
        catch(HibernateException e)
        {
            System.out.println("error HibernateException  in deleting the records " + e.getMessage());
            e.printStackTrace();
           
        }
        catch(Exception e2)
        {
            System.out.println("error Exception in deleting the records" );
            e2.printStackTrace();
           
        }
           
        finally{

           
            if(session!=null);
            {
                session.close();
            }
           
           
           
        }
       
    }

<code>

I am getting this error

java.lang.ClassCastException
at org.hibernate.type.IntegerType.set(IntegerType.java:39)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:39)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1626)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1972)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1918)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2158)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.uprr.app.eco.DeleteOldData.deleteOldData(DeleteOldData.java:148)
at com.uprr.app.eco.DeleteOldData.main(DeleteOldData.java:186
)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 11:38 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I can't figure out the error from what you've posted, you'll have to debug that. You could try using more, smaller transactions to narrow down exactly which bit is causing the error. Obviously you'll have to go back to using a single transaction, once your code passes its tests.

I have a few hints though:

"if (iter.hasNext()) session.delete(iter.next());" isn't going to help much. What if there are two items in there? You need a while loop, not an if statement.

You are deleting items without removing them from their sets. This may well be the cause of your exception. For sets with cascade="delete-orphan" (which is probably what you want, rather than cascade="delete"), a better way to delete items is like this:
Code:
parent.getItems().remove(child);
session.update(parent);
Even though you haven't called delete(child) anywhere, hibernate figures out that the child is an orphan (no parent points to it any more) and therefore deletes it.

You have a few cascading sets in your mapping: ecoHzrdEmgyResps, ecoCommodities, etc. You don't need to iterate through those sets to delete things in them, so you can remove code that does that. So long as you use "session.delete(cmdy)" on an object that you have loaded using hibernate, those deletes will automatically cascade. The problem (in your first post) was that you weren't using session.delete, you were using Query.executeUpdate().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 12:16 am 
Newbie

Joined: Mon Mar 13, 2006 9:46 pm
Posts: 7
I am posting the whole code. I have changed to cascade="delete-orphan" but still getting the same error. Is there a problem with the maping

Code:
/*
* Created on Mar 11, 2006
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.uprr.app.eco;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.uprr.app.eco.persistenceDelete.EcoCmdyDelete;
import com.uprr.app.eco.util.HibernateUtil;


public class DeleteOldData {
   
    public static final Logger logger = Logger.getLogger(DeleteOldData.class);   
    public static final Date TODAYS_RECORD_TIME1 =new Date();   
    public static final String PROP_FILE_STR = "prop.file";   
    public static final String HIBERNATE_CFG_FILE_STR = "hibernate.config";
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    public static final Timestamp TODAYS_RECORD_TIME =new Timestamp(System.currentTimeMillis());
    private static String hiberConfig = null;
    private static Session session = null;
   
   
   
    private static void  init()
    {
        TODAYS_RECORD_TIME.setHours(0);
        TODAYS_RECORD_TIME.setMinutes(0);
        TODAYS_RECORD_TIME.setSeconds(0);
        String propFile = System.getProperty(PROP_FILE_STR);
       
        if (propFile == null || propFile.trim().equals("")) {
            System.out.println("Usage java -D"+PROP_FILE_STR);
            System.exit(1);
        }
        Properties prop = new Properties();
        InputStream fin = null;
        try {
            fin = new FileInputStream(propFile);
            prop.load(new FileInputStream(propFile));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fin != null) {
                    fin.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        hiberConfig = (String) prop.get(HIBERNATE_CFG_FILE_STR);
       
        session=HibernateUtil.currentSession(hiberConfig);
       
       
    }
   
    /**
     *
     *
     */
    public static void deleteOldDataSQL()
    {
        try{
            String delSql = " delete EcoCmdyDelete where  lastUptdDt< :lastUpDt ";             
            Query delQry = session.createQuery(delSql);
            delQry.setTime("lastUpDt", TODAYS_RECORD_TIME );
            delQry.executeUpdate();
        }
        catch(Exception e)
        {
            System.out.println("deleteOldDataSQL" + e.getMessage());
           
        }
       
    }
   
    public  static void  deleteOldData()
    {
       
        Transaction tx=session.beginTransaction();
       
        try{     
           
           
           
            System.out.println("deleteOldData");
            String delSql = "from  EcoCmdyDelete c where  c.lastUptdDt< :lastUpDt ";             
            Query delQry = session.createQuery(delSql);
            delQry.setTime("lastUpDt", TODAYS_RECORD_TIME );         
            List qList =delQry.list();
            int count =0;
            if(qList!=null && qList.size()>0 )
            {
                Iterator i= qList.iterator();
              while(i.hasNext() && count<1)
              {
                  count++;
                  EcoCmdyDelete cmdy =(EcoCmdyDelete)i.next();                 
                 
//                  Iterator htdt=cmdy.getEcoHzmtDtls().iterator();
//                  if( htdt.hasNext())
//                  {
//                      session.delete(htdt.next());
//                  }
//                  Iterator htemr=cmdy.getEcoHzrdEmgyResps().iterator();
//                  if(htemr.hasNext())
//                  {
//                      session.delete(htemr.next());
//                  }
//                  Iterator htdtNms=cmdy.getEcoHzmtNameDescs().iterator();
//                  if( htdtNms.hasNext())
//                  {
//                      session.delete(htdtNms.next());
//                  }
//                  Iterator prdcls=cmdy.getEcoCommodities().iterator();
//                  if( prdcls.hasNext())
//                  {
//                      session.delete(prdcls.next());
//                  }
                 
                  session.delete( cmdy );
                 
              }
            }
           
           
//         
           
            tx.commit();
           
       
        }
        catch(HibernateException e)
        {
            System.out.println("error HibernateException  in deleting the records " + e.getMessage());
            e.printStackTrace();
           
        }
        catch(Exception e2)
        {
            System.out.println("error Exception in deleting the records" );
            e2.printStackTrace();
           
        }
           
        finally{

           
            if(session!=null);
            {
                session.close();
            }
           
           
           
        }
       
    }
    public static void main(String[]args)
    {
       
       
        try{
         logger.debug("Deleting records not updated with the current load");         
         init();
         deleteOldData();
//         deleteOldDataSQL();
         logger.debug("Successfully  Deleted older records from the database");
         }
        catch(Exception e )
        {
           
            logger.debug("Error in Deleting records: "+ e.getStackTrace());
        }
       
    }

}




From logs, they look ok


[Scheduling collection removes/(re)creates/updates]
[2006-03-13 21:53:57,956][DEBUG] [org.hibernate.event.def.AbstractFlushingEventListener] [Flushed: 0 insertions, 18038 updates, 1 deletions to 18039 objects]
[2006-03-13 21:53:57,956][DEBUG] [org.hibernate.event.def.AbstractFlushingEventListener] [Flushed: 0 (re)creations, 0 updates, 4 removals to 72156 collections]

03-13 21:53:57,956][DEBUG] [org.hibernate.event.def.AbstractFlushingEventListener] [executing flush]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.persister.entity.BasicEntityPersister] [Updating entity: [com.uprr.app.eco.persistenceDelete.EcoCmdyDelete#01 ]]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.jdbc.AbstractBatcher] [about to open PreparedStatement (open PreparedStatements: 0, globally: 0)]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.SQL] [update ECO.ECO_CMDY set HZRD_IND=?, EFF_DATE=?, CMDY_ABRV=?, INTL_HMZD_CODE=?, SVC_RQMT_CODE_1=?, SVC_RQMT_CODE_2=?, SVC_RQMT_CODE_3=?, WGT_TOLR_FCTR=?, CMDY_BASE_NBR=?, UNNA_NBR=?, CRTN_DT=?, CRTN_USER_ID=?, LAST_UPTD_DT=?, LAST_UPTD_USER_ID=?, CMDY_DESC=? where STCC_CODE=?]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.jdbc.AbstractBatcher] [preparing statement]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.persister.entity.BasicEntityPersister] [Dehydrating entity: [com.uprr.app.eco.persistenceDelete.EcoCmdyDelete#01 ]]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.StringType] [binding null to parameter: 1]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.DateType] [binding null to parameter: 2]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.StringType] [binding null to parameter: 3]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.StringType] [binding '000000' to parameter: 4]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.StringType] [binding '0' to parameter: 5]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.StringType] [binding '0' to parameter: 6]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.StringType] [binding '0' to parameter: 7]
[2006-03-13 21:53:57,972][DEBUG] [org.hibernate.type.IntegerType] [binding '0' to parameter: 8]
[2006-03-13 21:53:57,987][DEBUG] [org.hibernate.impl.SessionImpl] [closing session]
[2006-03-13 21:53:57,987][DEBUG] [org.hibernate.jdbc.AbstractBatcher] [closing JDBC connection (open PreparedStatements: 1, globally: 1) (open ResultSets: 0, globally: 0)]
[2006-03-13 21:53:57,987][DEBUG] [com.uprr.app.eco.DeleteOldData] [Successfully Deleted older records from the database]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 12:50 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Well, at the least there's an error in your catch logic: you're catching all exceptions in deleteOldData and discarding them, meaning you're not printing out the correct error message in main.

You're still getting the IntegerType ClassCastException? That means that some value in one of your objects is declared in the mapping to be an integer, but isn't an Integer in your java class. I can't see many integers in your mappings: wgtTolrFctr in EcoCmdyDelete, lineNbr in EcoHzrdEmgyRespDelete, and nameDescId in EcoHzmtDescLineDelete. Check the values in those every time you do a save or update.


Top
 Profile  
 
 Post subject: Cascade delete
PostPosted: Tue Mar 14, 2006 1:27 am 
Newbie

Joined: Mon Mar 13, 2006 9:46 pm
Posts: 7
I am now getting this exception when i try to delete
Code:
error HibernateException  in deleting the records Could not execute JDBC batch update
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
        at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
        at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:72)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:67)
        at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:148)
        at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:809)
        at org.hibernate.action.CollectionRemoveAction.execute(CollectionRemoveAction.java:22)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:138)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
        at com.uprr.app.eco.DeleteOldData.deleteOldData(DeleteOldData.java:163)
        at com.uprr.app.eco.DeleteOldData.main(DeleteOldData.java:190)
Caused by: java.sql.BatchUpdateException: ORA-01407: cannot update ("ECO"."ECO_HZRD_EMGY_RESP"."STCC_CODE") to NULL

        at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8726)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1722)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
        ... 15 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.