-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problems when trying to delete an object
PostPosted: Mon Dec 20, 2004 9:59 am 
Newbie

Joined: Fri Dec 17, 2004 6:10 am
Posts: 5
Hello,

I got a problem while trying to delete an instance of type 'Periode' : the first time i try, i got a DataAccessException because there are instances of 'InfosVentes' which are linked to instances of 'Articles' which belongs to the instance of 'Periode' i want to delete > normal and expected behaviour : i catch it and display a usr-friendly warning message.

But when i try again to delete the periode (or any other) again, i got a tomcat error message.

Does anyone can help me and tell me what's wrong in my code and why 2nd try doesn't behave as first? (code and mapping below)
Thanks in advance

P.S. : I also posted this topic on Spring Forum and they said I should rather post it on Hibernate Forum (what i did...) soplease don't tell me it's a spring subject...

Hibernate version: 2.1

Mapping documents:
Code:
<class name="Periode" table="periode">
  <id name="id" column="id_periode" type="integer" unsaved-value="null">
    <generator class="sequence">
      <param name="sequence">seq_periode</param>
    </generator>
  </id>
  <property name="libelle" column="lc_libelle" type="string" />
  <property name="dateDebut" column="da_date_debut" type="date" />
  <property name="dateFin" column="da_date_fin" type="date" />
  <property name="visibleMags" column="fl_visible_mag" type="boolean" />
  <bag name="articles" table="article" lazy="true" inverse="true" cascade="all-delete-orphan" order-by="co_sous_secteur, co_code">
    <key column="id_periode" />
    <one-to-many class="Article" />
  </bag>
</class>
   
<class name="Article" table="article">
  <id name="id" column="id_article" type="integer" unsaved-value="null">
    <generator class="sequence">
      <param name="sequence">seq_article</param>
    </generator>
  </id>
  <property name="code" column="co_code" type="string" />
  <property name="libelle" column="ll_libelle" type="string" />
  <many-to-one name="sousSecteur" column="co_sous_secteur" class="SousSecteur" cascade="none" outer-join="true" />
  <many-to-one name="periode" column="id_periode" class="Periode" cascade="none" outer-join="true" />
</class>

<class name="InfoVentes" table="info_ventes">
  <id name="id" column="id_info_ventes" type="integer" unsaved-value="null">
    <generator class="sequence">
      <param name="sequence">seq_info_ventes</param>
    </generator>
  </id>
  <property name="qteLivree" column="nb_qte_livree" type="integer" />
  <property name="qteVendue" column="nb_qte_vendue" type="integer" />
  <property name="qtePerdue" column="nb_qte_perdue" type="integer" />
  <property name="qteRecomm" column="nb_qte_preconisee" type="integer" />
  <property name="site" column="id_site" type="integer" />
  <many-to-one name="article" column="id_article" class="Article" cascade="none" outer-join="true" />
</class>


Code
Code:
public class PeriodeDAOImpl implements PeriodeDAO {
  public void delete(final Object obj) throws DataAccessException {
    hibernateTemplate.execute(new HibernateCallback() {
      public Object doInHibernate(Session session) throws HibernateException {
        session.delete(obj);
        session.flush();
        return null;
      }
    });
  }
}


Full stack trace of any exception that occurs:
Code:
Code:

java.lang.NullPointerException
   oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1581)
   oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:8540)
   org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:257)
   org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:257)
   net.sf.hibernate.impl.BatchingBatcher.addToBatch(BatchingBatcher.java:30)
   net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:583)
   net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
   net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
   net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2396)
   net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
   com.match.ventestrad.dao.hibernate.ObjectDAOImpl$2.doInHibernate(ObjectDAOImpl.java:78)
   org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
   com.match.ventestrad.dao.hibernate.ObjectDAOImpl.delete(ObjectDAOImpl.java:75)
   com.match.ventestrad.dao.hibernate.PeriodeDAOImpl.delete(PeriodeDAOImpl.java:91)
   com.match.ventestrad.service.PeriodeService$7.doInTransaction(PeriodeService.java:136)
   org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:114)
   com.match.ventestrad.service.PeriodeService.deletePeriode(PeriodeService.java:133)
   com.match.ventestrad.web.actions.GererPeriodesAction.perform(GererPeriodesAction.java:71)
   org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1787)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)
   org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Name and version of the database you are using: Oracle 8.1.7


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 11:39 am 
Newbie

Joined: Fri Dec 17, 2004 6:10 am
Posts: 5
As for my last topic, i got the answer in Spring forum :

In fact, I need to ensure that i am not reusing the session that caused the rollback. So i added
Code:
session.reconnect();

before
Code:
session.delete(obj);


It now works fine but I will see if there's no possible "optimization" of it : maybe I can "reconnect" only when the last session caused a rollback...

If anyone has an idea...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 11:51 am 
Newbie

Joined: Fri Dec 17, 2004 6:10 am
Posts: 5
Please ignore my last post : this "solution" doesn't work... (did get an error message but wasn't the one i was expecting)

still looking for the solution


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