How to get rid of the log when inserting record into partitioned table?

62 views
Skip to first unread message

Ильдар Гильфанов

unread,
Aug 4, 2014, 1:31:47 AM8/4/14
to grails-de...@googlegroups.com
Grails 2.2.4
postgreSQL 9.1
postgresql-9.2-1000.jdbc4.jar


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
     
}

}

Log errors after inserting record:

 Error 2014-08-03 14:45:07,206 [quartzScheduler_Worker-3] ERROR jdbc.AbstractBatcher  - Exception executing batch:
Message: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

Error 2014-08-03 14:45:07,248 [quartzScheduler_Worker-3] 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

Ильдар Гильфанов

unread,
Aug 5, 2014, 2:30:21 AM8/5/14
to grails-de...@googlegroups.com
Мay have to use a design sessionFactory.currentSession.createSQLQuery :-(

Ильдар Гильфанов

unread,
Aug 5, 2014, 4:34:54 AM8/5/14
to grails-de...@googlegroups.com
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
       
}

 
}

}


Reply all
Reply to author
Forward
0 new messages