I have a baseDAO
which contains methods for basic CRUD
operations. And for each operation we are doing getJpaTemplate.xxx()
operation.
The code is working fine in production, but now we have to write UTs
for DAO
layer and we are using DBUnit
.
I saw the examples and writing the DBUnit
classes, I observed that read operations work fine but Delete, update and Create operations are not working at all.
When we are trying to call DAO.save(object)
it doesn't throw any exception, it comes to next line but when I try to open the table and see the value, the new row is not inserted neither that transaction fails nor any exception is thrown.
I doubt there might be issue with connection.
For the reference I am attaching getConnection()
method.
protected IDatabaseConnection getConnection() throws Exception {
Connection con = dataSource.getConnection();
DatabaseConnection connection = new DatabaseConnection(con);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,new oracleDataTypeFactory());
return connection;
}
We have another method which is called in setup ()
for populating the data from the XML
file, which works fine. Just for reference I am adding code here.
protected void insertData (String xmlDataFilePath) {
IDatabaseConnection dbConnection= getConnection();
TransactionOperation.CLEAN_INSERT.execute(dbConnection,getDataSet(xmlDataFilePath));
connection = jPATransactionManager.getDataSource().getConnection();
connection.setAutoCommit(false);
savepoint = connection.setSavepoint("Data inserted in db");
dbConnection.close();
}
I am not sure without seeing the new row inserted in the db, how to proceed further.
Because I tried doing
getJpaTemplate().save(object);
getJpaTemplate().load(ClassName.class, object's id);
which returns me null
and in db table also there is no entry.
Any suggestions please?
Thanks in advance.
JE.
savepoint = connection.setSavepoint("Data inserted in db");
make sure when the savepoint gets committed? can you please put all relavant APIs code here?