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:
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:
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