Hello,
I have a simpe POJO that i am using hibernate to persist to my DB. Everything works fine, but when I enable 2nd level cacheing (ehcache), I get a StaleObjectStateException on the flush after updates.
Here's my mapping:
Code:
<hibernate-mapping>
<class name="ContentList" table="LIST" lazy="false"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true">
<cache usage="nonstrict-read-write"/>
<id name="tkey" column="LIST_KEY">
<generator class="KeyGenerator">
<param name="sequence">LIST_KEY_SEQ</param>
<param name="class">java.lang.String</param>
</generator>
</id>
<timestamp name="lastChangedDate" access="field" column="LAST_CHANGED_DATE"/>
<property name="lastChangedBy" access="field" column="LAST_CHANGED_BY" not-null="true"/>
<property name="title" access="field"/>
.
.
.
</hibernate-mapping>
Here's my ehcache config (works when I set maxElementsInMemory="0"):
Code:
<cache name="ContentList"
maxElementsInMemory="500"
eternal="false"/>
And this is the offending code:
Code:
@Test(groups = {"content-list"})
public void createContentList()
{
ContentList list = new ContentList();
list.setTitle(LIST_TITLE);
listService.saveContentList(list);
key = list.getKey();
assert(key != null);
}
@Test(groups = {"content-list"}, dependsOnMethods = {"createContentList"})
public void findContentList()
{
ContentList list = listService.getContentListByTitle(LIST_TITLE);
assert (list != null);
assert(list.getTitle().equals(LIST_TITLE));
}
@Test(groups = {"content-list"}, dependsOnMethods = {"findContentList"})
public void updateContentList()
{
ContentList list = listService.getContentList(key);
assert (list != null);
assert(list.getTitle().equals(LIST_TITLE));
list.setTitle(LIST_TITLE_MODIFIED);
listService.saveContentList(list);
//Get list back from DB
list = listService.getContentList(tkey);
assert(list.getTitle().equals(LIST_TITLE_MODIFIED));
}
Is this a cache configuration? Do i need to evict this item from the cache? If so, how so?
Thanks in advance for you help,
Matt