I have an integration test that runs fine agains MySql 5, H2 and HSQLDB but fails against Oracle 10g XE.
It fails with the following exception:
Quote:
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [com.thalasoft.learnintouch.core.domain.Link] with identifier [225]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
Here is the test:
Code:
@Before
public void beforeAnyTest() throws Exception {
linkCategory1 = linkCategoryDao.makePersistent(linkCategory1);
linkCategory0 = linkCategoryDao.makePersistent(linkCategory0);
}
public void testDelete() {
assertEquals(2, linkCategoryDao.countAllRows());
linkCategoryDao.makeTransient(linkCategory0);
assertEquals(1, linkCategoryDao.countAllRows());
Link link = new Link();
link.setName("Google");
link.setUrl("www.google.com");
link.setLinkCategory(linkCategory1);
link = linkDao.makePersistent(link);
try {
linkCategoryDao.makeTransient(linkCategory1);
linkCategoryDao.flush();
fail();
} catch (DataAccessException e) {
logger.debug("Make sure a parent cannot be deleted if currently being used by a child. Catching the DataAccessException thrown by an illigal delete");
} finally {
linkCategoryDao.clear();
}
assertEquals(1, linkCategoryDao.countAllRows());
link.setLinkCategory(null);
link = linkDao.makePersistent(link);
linkCategoryDao.makeTransient(linkCategory1);
assertEquals(0, linkCategoryDao.countAllRows());
}
It fails from the last line linkCategoryDao.countAllRows()
It is strange that it works on all database servers except Oracle.
Here is my DAO setup:
Code:
@Override
public Page<LinkCategory> findAll(final int pageNumber, final int pageSize) {
Criteria criteria = getSession().createCriteria(getPersistentClass());
criteria.addOrder(Order.asc("name"));
Page<LinkCategory> page = getPage(pageNumber, pageSize, criteria);
return page;
}
I thought the cascade all in the mapping was maybe the cause for this error, so I removed it, but it did not change the issue and the error remained.
Here is the mapping:
Code:
<class name="com.thalasoft.learnintouch.core.domain.LinkCategory" table="link_category" dynamic-insert="true" dynamic-update="true">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native"><param name="sequence">sq_id_link_category</param></generator>
</id>
<version name="version" type="int">
<column name="version" not-null="true" />
</version>
<property name="name" type="string">
<column name="name" length="50" not-null="true" />
</property>
<property name="description" type="string">
<column name="description" not-null="false" />
</property>
<set name="links" inverse="true" order-by="list_order" cascade="all">
<key column="category_id" />
<one-to-many class="com.thalasoft.learnintouch.core.domain.Link" />
</set>
</class>
Any clue ?