IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

Comment catcher org.hibernate.util.JDBCExceptionReporter


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    42
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 42
    Points : 44
    Points
    44
    Par défaut Comment catcher org.hibernate.util.JDBCExceptionReporter
    Bonjour,


    Lorsque j'essaye d'insérer un enregistrement dans la table j'obtiens l'exception suivante : org.hibernate.util.JDBCExceptionReporter.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    Hibernate: insert into TOTO.PRODUIT (LIBELLE, TYPE_GFR, CONSULTATION, VERS_LIBRE_ACTIF, VERS_LIBRE_MNT_MIN, VERS_LIBRE_MNT_MAX, CODE) values (?, ?, ?, ?, ?, ?, ?)
    18 - 10:30:05,171 ERROR org.hibernate.util.JDBCExceptionReporter - ORA-01400: impossible d'insérer NULL dans ("TOTO"."PRODUIT"."LIBELLE")
     
    18 - 10:30:05,171 ERROR org.hibernate.util.JDBCExceptionReporter - ORA-01400: impossible d'insérer NULL dans ("TOTO"."PRODUIT"."LIBELLE")
     
    18 - 10:30:05,171 ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
    	at fmwk.test.database.TestDatabaseSpringAbstract.flushSession(TestDatabaseSpringAbstract.java:274)
    	at fmwk.test.database.TestDatabaseSpringAbstract.tearDown(TestDatabaseSpringAbstract.java:208)
    	at junit.framework.TestCase.runBare(TestCase.java:130)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.sql.BatchUpdateException: ORA-01400: impossible d'insérer NULL dans ("TOTO"."PRODUIT"."LIBELLE")
     
    	at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
    	at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
    	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
    	... 20 more

    C'est normal car je n'ai pas renseigné le champ LIBELLE qui est obligatoire.

    Ma question c'est comment catcher cette exception elle ne dérive que de java.lang.Object http://www.hibernate.org/hib_docs/v3...nReporter.html

    Voici mon code, mon problème est que sur le saveProduit au lieu de passer dans le catch Exception je saute à la fin de la fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
        public void testCreerProduit() {
     
            IProduitBO produit = new ProduitBO();
     
            produit.setCodeProduit("12456");
            try {
                service.saveProduit(produit);
            } catch (HibernateJdbcException e) {
                System.out.println("COUCOU ICI");
                System.out.println(e.toString());
                logger.error("COUCOU ICI");
                logger.error(e.toString());
                assertTrue(true);
            } catch (org.hibernate.exception.ConstraintViolationException e) {
                System.out.println("OU ICI");
                System.out.println(e.toString());
                logger.error("OU ICI");
                logger.error(e.toString());
            } catch (Exception e) {
                System.out.println("OU ENCORE ICI");
                System.out.println(e.toString());
                fail("Erreur exception non traitée.");
            }
     
        }
    Une idée ?


    Jemini

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 74
    Points : 83
    Points
    83
    Par défaut
    A mon avis, un meilleur design consiste à valider les contraintes d'intégrités avant qu'elles ne génèrent une erreur !
    Hibernate Validator par exemple devrais te permettre un truc adapté...



    Citation Envoyé par jemini_fr Voir le message
    Bonjour,


    Lorsque j'essaye d'insérer un enregistrement dans la table j'obtiens l'exception suivante : org.hibernate.util.JDBCExceptionReporter.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    Hibernate: insert into TOTO.PRODUIT (LIBELLE, TYPE_GFR, CONSULTATION, VERS_LIBRE_ACTIF, VERS_LIBRE_MNT_MIN, VERS_LIBRE_MNT_MAX, CODE) values (?, ?, ?, ?, ?, ?, ?)
    18 - 10:30:05,171 ERROR org.hibernate.util.JDBCExceptionReporter - ORA-01400: impossible d'insérer NULL dans ("TOTO"."PRODUIT"."LIBELLE")
     
    18 - 10:30:05,171 ERROR org.hibernate.util.JDBCExceptionReporter - ORA-01400: impossible d'insérer NULL dans ("TOTO"."PRODUIT"."LIBELLE")
     
    18 - 10:30:05,171 ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
    	at fmwk.test.database.TestDatabaseSpringAbstract.flushSession(TestDatabaseSpringAbstract.java:274)
    	at fmwk.test.database.TestDatabaseSpringAbstract.tearDown(TestDatabaseSpringAbstract.java:208)
    	at junit.framework.TestCase.runBare(TestCase.java:130)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.sql.BatchUpdateException: ORA-01400: impossible d'insérer NULL dans ("TOTO"."PRODUIT"."LIBELLE")
     
    	at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
    	at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
    	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
    	... 20 more

    C'est normal car je n'ai pas renseigné le champ LIBELLE qui est obligatoire.

    Ma question c'est comment catcher cette exception elle ne dérive que de java.lang.Object http://www.hibernate.org/hib_docs/v3...nReporter.html

    Voici mon code, mon problème est que sur le saveProduit au lieu de passer dans le catch Exception je saute à la fin de la fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
        public void testCreerProduit() {
     
            IProduitBO produit = new ProduitBO();
     
            produit.setCodeProduit("12456");
            try {
                service.saveProduit(produit);
            } catch (HibernateJdbcException e) {
                System.out.println("COUCOU ICI");
                System.out.println(e.toString());
                logger.error("COUCOU ICI");
                logger.error(e.toString());
                assertTrue(true);
            } catch (org.hibernate.exception.ConstraintViolationException e) {
                System.out.println("OU ICI");
                System.out.println(e.toString());
                logger.error("OU ICI");
                logger.error(e.toString());
            } catch (Exception e) {
                System.out.println("OU ENCORE ICI");
                System.out.println(e.toString());
                fail("Erreur exception non traitée.");
            }
     
        }
    Une idée ?


    Jemini

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    42
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 42
    Points : 44
    Points
    44
    Par défaut
    ok merci je vais regarder ça.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 13/07/2011, 10h42
  2. Réponses: 13
    Dernier message: 27/04/2009, 16h37
  3. Réponses: 3
    Dernier message: 12/06/2008, 16h41
  4. [Exception] Comment catcher une runtime exception ?
    Par bulbo dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 16/06/2005, 09h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo