I have the following problem, in my REST server application (Jersey+ActiveJDBC+Shiro+TomcatJDBC) running in Tomcat 8 and database is PostgreSQL also it running in VPS.
Sometimes after large/many CRUD activity via REST application, the inserted data in database is not exist.
Note: I am using insert in ActiveJDBC since i have custom PK and not using any cache.
For example: via REST when calling total data it says 100, but when checking database directly it says 80. Then if i restart Tomcat, the REST will respond 80, thus the data is gone...
I already debug all potential error (Checked Tomcat Log, Postgresql Log, and App log, also the VPS) but found nothing! The inserted data it just like never inserted.
The data gone is happen sporadically, and I can't reproduce it. Thus I can't fix the bug.
(Edited, wrong reference before):
Then I found this Q&A : Hibernate not saving Object in the Database
Is there possibility ActiveJDBC have flush problem like above, since like Q&A above its only happen with PostgreSQL.
Saving Code :
try(DB db = new DB()){
db.open(DataSourcePool.getInstance().ds_pooled);
dbModel dbModel = new dbModel();
dbModel.setPojoModel(PojoModel);
CheckRulesCreate(dbModel); // Business Rule Check, throw on Fail
if (dbModel.insert())
return Response.status(201).entity(new Outputs("OK",201,"Data saved!")).build();
}
Data Source Pool :
//Singelton Based On Bill Pugh Singeltom Design
import org.apache.tomcat.jdbc.pool.DataSource;
DataSource ds = new DataSource();
ds.setDriverClassName("org.postgresql.Driver");
ds.setUrl("jdbc:postgresql://localhost/database");
ds.setUsername("blahblah");
ds.setPassword("hisshiss");
ds.setInitialSize(10);
ds.setMaxActive(300);
ds.setMinIdle(2);
ds.setValidationQuery("select 1");
ds.setTestOnBorrow(true);
ds.setRemoveAbandoned(true);
ds.setRemoveAbandonedTimeout(60);
ds.setMaxWait(10000);
ds.setName("DataSourcePool");