Thanks for the help, its muchly appreciated. Again all I think I need to do is somehow remove the object from the session if an exception is thrown when I call flush (in the DAO code not at the commit code)
I am using Informix 9.2
Autocommit is off
the codeCode:
Transaction transaction;
try {
transaction = DAOFactory.getCurrentSession().beginTransaction();
// this calls insert for me
// the trigger will fire here and will raise an exception
occupationalHistoryDAO.insert(occupationalHistory);
} catch(Exception e) {
e.printStackTrace();
}
try {
// i still want to commit because this is part of a batch process and if a record
// fails because of the trigger it is logged and needs to be handled manually
// the trigger is activated here as well.
// I dont want this to happen
transaction.commit();
} catch(Exception e) {
e.printStackTrace();
} finally {
if(transaction.isActive()) {
transaction.rollback();
}
}
the log
Environment 10:59:11,585 INFO Environment:479 - Hibernate 3.1.2
Environment 10:59:11,632 INFO Environment:509 - hibernate.properties not found
Environment 10:59:11,632 INFO Environment:525 - using CGLIB reflection optimizer
Environment 10:59:11,632 INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
Configuration 10:59:11,804 INFO Configuration:1308 - configuring from resource: /hibernate.cfg.xml
Configuration 10:59:11,804 INFO Configuration:1285 - Configuration resource: /hibernate.cfg.xml
Configuration 10:59:13,929 INFO Configuration:1419 - Configured SessionFactory: null
DriverManagerConnectionProvider 10:59:14,335 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
DriverManagerConnectionProvider 10:59:14,335 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
DriverManagerConnectionProvider 10:59:14,335 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
SettingsFactory 10:59:14,976 INFO SettingsFactory:77 - RDBMS: Informix Dynamic Server, version: 9.40.UC3
SettingsFactory 10:59:14,991 INFO SettingsFactory:78 - JDBC driver: IBM Informix JDBC Driver for IBM Informix Dynamic Server, version: 2.21.JC5
Dialect 10:59:15,023 INFO Dialect:103 - Using dialect: org.hibernate.dialect.InformixDialect
TransactionFactoryFactory 10:59:15,038 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
TransactionManagerLookupFactory 10:59:15,070 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
SettingsFactory 10:59:15,070 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): enabled
SettingsFactory 10:59:15,070 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
SettingsFactory 10:59:15,085 INFO SettingsFactory:144 - Scrollable result sets: enabled
SettingsFactory 10:59:15,085 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
SettingsFactory 10:59:15,085 INFO SettingsFactory:160 - Connection release mode: auto
SettingsFactory 10:59:15,085 INFO SettingsFactory:187 - Default batch fetch size: 1
SettingsFactory 10:59:15,085 INFO SettingsFactory:191 - Generate SQL with comments: disabled
SettingsFactory 10:59:15,085 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
SettingsFactory 10:59:15,085 INFO SettingsFactory:338 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
ASTQueryTranslatorFactory 10:59:15,101 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
SettingsFactory 10:59:15,101 INFO SettingsFactory:203 - Query language substitutions: {}
SettingsFactory 10:59:15,101 INFO SettingsFactory:209 - Second-level cache: enabled
SettingsFactory 10:59:15,101 INFO SettingsFactory:213 - Query cache: disabled
SettingsFactory 10:59:15,101 INFO SettingsFactory:325 - Cache provider: org.hibernate.cache.EhCacheProvider
SettingsFactory 10:59:15,116 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
SettingsFactory 10:59:15,116 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
SettingsFactory 10:59:15,116 INFO SettingsFactory:257 - Echoing all SQL to stdout
SettingsFactory 10:59:15,132 INFO SettingsFactory:264 - Statistics: disabled
SettingsFactory 10:59:15,132 INFO SettingsFactory:268 - Deleted entity synthetic identifier rollback: disabled
SettingsFactory 10:59:15,132 INFO SettingsFactory:283 - Default entity-mode: pojo
SessionFactoryImpl 10:59:15,226 INFO SessionFactoryImpl:153 - building session factory
SessionFactoryObjectFactory 10:59:16,023 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
Hibernate: select this_.point_type_id as point1_3_0_, this_.point_type_name as point2_3_0_ from sp_point_type this_
Hibernate: select this_.mark_condition_id as mark1_5_0_, this_.mark_condition_name as mark2_5_0_ from sp_mark_condition_type this_
Hibernate: insert into sp_occupational_history (survey_date, local_name, mark_condition_id, mark_pid, point_pid, survey_number) values (?, ?, ?, ?, ?, ?)
JDBCExceptionReporter 10:59:18,679 WARN JDBCExceptionReporter:71 - SQL Error: -525, SQLState: 23000
JDBCExceptionReporter 10:59:18,679 ERROR JDBCExceptionReporter:72 - Failure to satisfy referential constraint Survey Mark PID does not exist.
AbstractFlushingEventListener 10:59:18,695 ERROR AbstractFlushingEventListener:299 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [nrm.spam.dao.occhist.OccupationalHistoryTO]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at nrm.spam.dao.occhist.hibernate.OccupationalHistoryDAOHibernateImpl.insert(OccupationalHistoryDAOHibernateImpl.java:39)
at nrm.spam.dao.occhist.test.OccupationalHistoryDAOTest.testInsertWithInvalidPointPID(OccupationalHistoryDAOTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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 com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.main(Unknown Source)
Caused by: java.sql.SQLException: Failure to satisfy referential constraint Survey Mark PID does not exist.
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3082)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3396)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2259)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2179)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:721)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:305)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:882)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:281)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
... 25 more
nrm.common.dao.exceptions.DAOException: org.hibernate.exception.ConstraintViolationException: could not insert: [nrm.spam.dao.occhist.OccupationalHistoryTO]
at nrm.spam.dao.occhist.hibernate.OccupationalHistoryDAOHibernateImpl.insert(OccupationalHistoryDAOHibernateImpl.java:43)
at nrm.spam.dao.occhist.test.OccupationalHistoryDAOTest.testInsertWithInvalidPointPID(OccupationalHistoryDAOTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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 com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.main(Unknown Source)
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [nrm.spam.dao.occhist.OccupationalHistoryTO]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at nrm.spam.dao.occhist.hibernate.OccupationalHistoryDAOHibernateImpl.insert(OccupationalHistoryDAOHibernateImpl.java:39)
... 16 more
Caused by: java.sql.SQLException: Failure to satisfy referential constraint Survey Mark PID does not exist.
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3082)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3396)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2259)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2179)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:721)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:305)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:882)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:281)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
... 25 more
Hibernate: insert into sp_occupational_history (survey_date, local_name, mark_condition_id, mark_pid, point_pid, survey_number) values (?, ?, ?, ?, ?, ?)
JDBCExceptionReporter 10:59:24,945 WARN JDBCExceptionReporter:71 - SQL Error: -525, SQLState: 23000
JDBCExceptionReporter 10:59:24,945 ERROR JDBCExceptionReporter:72 - Failure to satisfy referential constraint Survey Mark PID does not exist.
AbstractFlushingEventListener 10:59:24,945 ERROR AbstractFlushingEventListener:299 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [nrm.spam.dao.occhist.OccupationalHistoryTO]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at nrm.spam.test.AbstractSPAMTestCase.tearDown(AbstractSPAMTestCase.java:245)
at nrm.spam.dao.occhist.test.OccupationalHistoryDAOTest.tearDown(OccupationalHistoryDAOTest.java:167)
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 com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.main(Unknown Source)
Caused by: java.sql.SQLException: Failure to satisfy referential constraint Survey Mark PID does not exist.
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3082)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3396)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2259)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2179)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:721)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:305)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:882)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:281)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
... 22 more
org.hibernate.exception.ConstraintViolationException: could not insert: [nrm.spam.dao.occhist.OccupationalHistoryTO]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at nrm.spam.test.AbstractSPAMTestCase.tearDown(AbstractSPAMTestCase.java:245)
at nrm.spam.dao.occhist.test.OccupationalHistoryDAOTest.tearDown(OccupationalHistoryDAOTest.java:167)
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 com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.main(Unknown Source)
Caused by: java.sql.SQLException: Failure to satisfy referential constraint Survey Mark PID does not exist.
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3082)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3396)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2259)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2179)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:721)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:305)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:882)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:281)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
... 22 more
JDBCExceptionReporter 10:59:24,976 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 01I01
JDBCExceptionReporter 10:59:24,976 WARN JDBCExceptionReporter:49 - Database has transactions
JDBCExceptionReporter 10:59:24,976 WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 01I04
JDBCExceptionReporter 10:59:24,976 WARN JDBCExceptionReporter:49 - Database selected