try{
fooBar.save(flush:true, failOnError:true)
}catch(org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException ex){
if(ex.message.indexOf('row count: 0; expected: 1') == -1){
throw ex
}
}
CREATE TABLE parttemp
(
id serial NOT NULL,
test_field integer,
CONSTRAINT parttemp_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
CREATE TABLE parttemp_1
(
id integer NOT NULL DEFAULT nextval('parttemp_id_seq'::regclass),
test_field integer,
CONSTRAINT parttemp_1_pkey PRIMARY KEY (id)
)
INHERITS (parttemp)
WITH (
OIDS=FALSE
);
CREATE OR REPLACE FUNCTION insert_parttemp_trig()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO parttemp_1 VALUES (NEW.*);
RETURN NULL;
END; $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
CREATE TRIGGER insert_parttemp_trigger
BEFORE INSERT
ON parttemp
FOR EACH ROW
EXECUTE PROCEDURE insert_parttemp_trig();
import org.hibernate.SessionFactory
import foo.bar.PartTemp
class BootStrap {
def init = { servletContext ->
//new PartTemp(test_field: 27999).save(flush:true, failOnError:true)
//
//ERROR jdbc.AbstractBatcher - Exception executing batch:
//Message: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
//
//ERROR events.PatchedDefaultFlushEventListener - Could not synchronize database state with session
//Message: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
def sqlQuery = sessionFactory.currentSession.createSQLQuery("INSERT INTO parttemp(test_field) VALUES(?)")
sqlQuery.setInteger(0, 27999)
sqlQuery.executeUpdate()
PartTemp.createCriteria().get {
projections {
max("test_field")
}
}.each{
println it==27999
}
}
}