Hi,
I have a DAO method that is coded as such:
Code:
public Page<Document> findPublished(final int pageNumber, final int pageSize) {
Criteria criteria = getSession().createCriteria(getPersistentClass());
criteria.add(Restrictions.ne("hide", true));
criteria.addOrder(Order.asc("documentCategory")).addOrder(Order.asc("listOrder"));
logger.debug("================>>> Size1: " + criteria.list().size());
Page<Document> page = getPage(pageNumber, pageSize, criteria);
logger.debug("================>>> Size2: " + page.getPageItems().size());
return page;
}
The method is called by an integration test fed with the following data:
Code:
public DocumentDaoTest() {
documentCategory0 = new DocumentCategory();
documentCategory0.setName("images");
documentCategory0.setListOrder(1);
document0 = new Document();
document0.setFilename("image0.png");
document0.setListOrder(1);
document0.setDocumentCategory(documentCategory0);
document1 = new Document();
document1.setFilename("pdf1.pdf");
document1.setListOrder(2);
document2 = new Document();
document2.setFilename("pdf2.pdf");
document2.setListOrder(3);
document2.setDocumentCategory(documentCategory0);
}
public void beforeAnyTest() throws Exception {
document1 = documentDao.makePersistent(document1);
document0 = documentDao.makePersistent(document0);
document2 = documentDao.makePersistent(document2);
}
public void testFindPublished() {
document0.setHide(true);
Page<Document> page = documentDao.findPublished(0, 0);
List<Document> documents = page.getPageItems();
assertEquals(2, documents.size());
assertEquals(document1.getListOrder(), documents.get(0).getListOrder());
assertEquals(document2.getListOrder(), documents.get(1).getListOrder());
}
The test works fine against MySql, H2 and HSQLDB.
But when the test is run against Oracle, the list size is 3 instead of the expected 2.
Here is the console output:
Quote:
testFindPublished(com.thalasoft.learnintouch.core.dao.DocumentDaoTest) Time elapsed: 12.744 sec <<< FAILURE!
java.lang.AssertionError: expected:<2> but was:<3>
I output the actual sql statements with the log4jdbc library and it shows:
Quote:
insert into document (version, filename, hide, secured, list_order, id) values (0, 'pdf1.pdf', 0, 0, 2, 776)
insert into document_category (version, name, list_order, id) values (0, 'images', 1, 477)
insert into document (version, filename, hide, secured, list_order, category_id, id) values (0, 'image0.png', 0, 0, 1, 477, 777)
insert into document (version, filename, hide, secured, list_order, category_id, id) values (0, 'pdf2.pdf', 0, 0, 3, 477, 778)
update document set version=1, hide=1 where id=777 and version=0
select this_.id as id99_0_, this_.version as version99_0_, this_.reference as reference99_0_, this_.description as descript4_99_0_, this_.filename as filename99_0_, this_.hide as hide99_0_, this_.secured as secured99_0_, this_.list_order as list8_99_0_, this_.category_id as category9_99_0_ from document this_ where this_.hide<>1 order by this_.category_id asc, this_.list_order asc
We can see there are 3 inserts into the document table with 1 update.