-->
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: "Uncatchable" DataAccessException with Spring &
PostPosted: Fri Dec 17, 2004 6:29 am 
Newbie

Joined: Fri Dec 17, 2004 6:10 am
Posts: 5
Hibernate version: 2.1

Full stack trace of any exception that occurs:
org.springframework.dao.DataIntegrityViolationException: (HibernateTemplate): data integrity violated by SQL 'null'; nested exception is java.sql.BatchUpdateException: ORA-02292: integrity constraint (VENTES_TRAD.FK_INFO_VEN_CONCERNE_ARTICLE) violated - child record found

org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:82)
org.springframework.orm.hibernate.HibernateTransactionManager.convertJdbcAccessException(HibernateTransactionManager.java:516)
org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:394)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:314)
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:126)
com.match.ventestrad.service.PeriodeService.deletePeriode(PeriodeService.java:133)
com.match.ventestrad.web.actions.GererPeriodesAction.perform(GererPeriodesAction.java:66)
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

MAPPING Of objects :
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>

<!-- Mapping de la classe com.match.ventestrad.domain.Article -->
<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="periode" column="id_periode" class="Periode" cascade="none" outer-join="true" />
</class>


My problem : i'm trying to delete an object 'Periode' which contains a list of objects 'Article' with this code :

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


and i got an exception because of an integrity violation (that's normal). But what is not normal is that i can't manage to catch the exception so as to write a 'decent' message instead of having an horrible stacktrace on my html page...
Anyone has an idea why the Exception is not caught?

(DataIntegrityViolationException is a subclass od DataAccessException so I thought it would be caught...)
Thx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 9:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
org.springframework.dao.DataIntegrityViolationException


please ask spring about this.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 5:23 am 
Newbie

Joined: Fri Dec 17, 2004 6:10 am
Posts: 5
Thanks to Croco, a Spring user, I got the solution to my problem :

Quote:
The changes made in your savePeriodes() method get flushed to the database only before the transaction completes. The calls to the hibernate session get transalated into actual calls to the database only when the transaction is about to end. If you want to explicitelly flush your changes and catch the exception as you want in your code, you need to add a hibernateSession.flush() in your PeriodeDAOImpl code. The simpler way is to let it bubble up in the web layer and put there (in the controller) the appropriate exception handling.

regards, Croco.


Thanks again for help.


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.