java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -


i spotted odd behavior in hsql, seems when using database transactions database contraints not checked during sql inserts during sql commits , when transaction rollbacked not checked @ all.

i have spring integration test:

@runwith(springjunit4classrunner.class) @transactionconfiguration(defaultrollback=true, transactionmanager="transactionmanager") @transactional public class integrationtest { 

with test creates new entity instance , calls hibernate's persist on it.

it works fine, when change defaultrollback false fails:

caught exception while allowing testexecutionlistener [org.springframework.test.context.transaction.transactionaltestexecutionlistener@517a2b0] process 'after' execution test: method [public void myintegrationtest.test()], instance [myintegrationtest@546e61d5], exception [null] org.springframework.dao.dataintegrityviolationexception: not execute statement; sql [n/a]; constraint [null]; nested exception org.hibernate.exception.constraintviolationexception: not execute statement   @ org.springframework.orm.hibernate4.sessionfactoryutils.converthibernateaccessexception(sessionfactoryutils.java:161)   @ org.springframework.orm.hibernate4.hibernatetransactionmanager.converthibernateaccessexception(hibernatetransactionmanager.java:681)   @ org.springframework.orm.hibernate4.hibernatetransactionmanager.docommit(hibernatetransactionmanager.java:563)   @ org.springframework.transaction.support.abstractplatformtransactionmanager.processcommit(abstractplatformtransactionmanager.java:757)   @ org.springframework.transaction.support.abstractplatformtransactionmanager.commit(abstractplatformtransactionmanager.java:726) ... caused by: java.sql.sqlintegrityconstraintviolationexception: integrity constraint violation: not null check constraint; sys_ct_10120 table: mytable column: mycolumn 

this seems correct, because indeed code did not set mycolumn atttribute in entity before calling persist on it.

questions:

  • why database contraints not checked during inserts during commits?
  • why when doing rollback database contraints not checked?

[posting @a_horse_with_no_name's answer, able close question].

my orm (hibernate) not sending queries database until commit. if transaction ended rollback queries not sent database @ all. making sure flush() called (flushmode.always) after every persis() fixed issue.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -