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: Problème de suppression dans une liste
PostPosted: Sat Sep 23, 2006 10:57 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 7:16 pm
Posts: 20
Bonjour,

J'ai une page qui contient une list d'article et je n'arrive pas à supprimer un des articles. L'erreur qui m'est envoyé est la suivante :

Code:
6:54:53,390 INFO  [STDOUT] Hibernate: update T_ARTICLE set ARTICLE_TEXT=?, ARTICLE_PLACEMENT=?, ARTICLE_HAUTEUR=?, ARTICLE_LONGUEUR=?, ARTICLE_TITRE=? where ARTICLE_ID=?
16:54:53,484 INFO  [STDOUT] Hibernate: update T_ARTICLE set PAGE_ID=null, ARTICLE_ID=null where PAGE_ID=? and ARTICLE_ID=?
16:54:53,484 INFO  [STDOUT] Hibernate: update T_ARTICLE set PAGE_ID=null, ARTICLE_ID=null where PAGE_ID=? and ARTICLE_ID=?
16:54:53,484 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
16:54:53,484 ERROR [JDBCExceptionReporter] L'élément du batch 0 update T_ARTICLE set PAGE_ID=null, ARTICLE_ID=null where PAGE_ID=0 and ARTICLE_ID=6 a été annulé. Appeler getNextException pour en connaître la cause.
16:54:53,484 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
16:54:53,484 ERROR [JDBCExceptionReporter] ERROR: null value in column "article_id" violates not-null constraint
16:54:53,484 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session


Ce que je fais exactement lors de ma suppression :
Code:
public void deleteArticle(int idPage,int idArticle) {
      Context ctx;
      try {
         ctx = new InitialContext();
         HibernateManagerLocalHome managerLocalHome = (HibernateManagerLocalHome) ctx.lookup("HibernateManagerLocal");
         HibernateManagerLocal managerLocal = managerLocalHome.create();
         Article article = (Article)managerLocal.get(Article.class,idArticle);
         Page page =  (Page)managerLocal.get(Page.class,idPage);
         page.getArticles().remove(article);
         managerLocal.update(page);
      }catch (Exception e) {
         e.printStackTrace();
      }
   }



Mon mapping :
Code:
<?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>
    <class name="com.aetys.easyportal.easyWeb3.site.modele.Page" table="T_PAGE">
        <id name="id" column="PAGE_ID">
                        <generator class="sequence">
                <param name="sequence">page_sequence</param>
        </generator></id>
        <property column="PAGE_TITRE" name="titre" type="string"></property>
        <property column="PAGE_PLACEMENT" name="placement" type="int"></property>
        <property column="PAGE_TEMPLATE" name="template" type="string"></property>
     
         <list name="articles" lazy="false" table="T_ARTICLE"  cascade="all-delete-orphan"  >
             <key column="PAGE_ID"/>
             <list-index column="ARTICLE_ID"/>
              <one-to-many  class="com.aetys.easyportal.easyWeb3.site.modele.Article" />
       </list>
          <list name="sousPages" lazy="false" table="T_PAGE"  cascade="all-delete-orphan"  >
             <key column="PAGE_MERE"/>
             <list-index column="PAGE_ID"/>
              <one-to-many  class="com.aetys.easyportal.easyWeb3.site.modele.Page" />
       </list>
     </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 7:40 am 
Newbie

Joined: Mon Oct 02, 2006 6:10 am
Posts: 6
La ligne :
[JDBCExceptionReporter] ERROR: null value in column "article_id" violates not-null constraint
me semble suffisamment explicite.

Hibernate génére l'erreur car il essaye d' "updater" une ligne qui respecte pas le formalisme qu'on lui à dit :
Tu essaye d' "updater" une ligne dont article_id est NULL alors qu'il ne devrait pas l'être.
(le 'not-null' est sûrement indiqué dans ton fichier de mapping Hibernate, car si c'était indiqué dasn ta Base de Données, tu n'aurais pas pû rentrer cette ligne dans ta base, sauf peut-être si tu as fait un alter table .... )


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 9:35 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 7:16 pm
Posts: 20
Bon finalement j'ai trouvé :)

Hibernate faisait un update à null au lieu d'un delete (delete-orphan oblige) tout simplement parceque j'avais oublié de mettre inverse = true dans ma collection (lien bidirectionnel).


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.