Hello,
I've got a bit of a weird issue, quite a serious one as far as my application goes!
I've got an object (lets call it a 'page') that contains a bunch of 'SharedItems' which represents users of the system that the page is shared to.
the mapping looks like this:
Code:
<class name="Page" >
...
<list name="sharedItems" cascade="all, delete-orphan" >
<key column="page_id" />
<index column="page_index"/>
<one-to-many class="SharedItem" />
</list>
...
</class>
Code:
<class name="SharedItem">
...
<many-to-one name="page"
column="page_id"
class="Page"
update="false"
insert="false" />
...
</class>
And the annotations look like this:
in page class:
Code:
@Indexed
public class Page{
...
@IndexedEmbedded(depth=2)
private List<SharedItem> sharedItems = new ArrayList<SharedItem>();
...
}
in SharedItem class:
Code:
public class SharedItem{
...
@ContainedIn
private Page page;
...
}
regarding the (depth=2), the SharedItem contains 2 more collections but I don't believe they are the cause of the problem...
The way I update this collection in my 'page' class is to remove everything from the list and then put in all brand new objects (some of which are almost identical to the ones I removed but they are NEW objects with no ID's etc. so this should not matter.)
The code that does it looks like this:
Code:
//First remove all existing items.
page.getSharedItems().removeAll(
page.getSharedItems()
);
//add in new sharedItems list that was passed into the method
Iterator<SharedItem> iterNewItems = newSharedItems.iterator();
while(iterNewItems.hasNext()){
page.getSharedItems().add(iterNewItems.next());
}
DAO.savePage(page);
After this action completes, my search indexes seem to go crazy and all my indexes are gone. The files are still there but none of my hibernate search queries ever get any results.
If I manually run my initialise method which cycles through all indexed objects and indexes them, then everything is indexed fine again, but hibernate doesn't seem capable of handling this collection update about 90% of the time without me having to manually initialise everything straight after. Any ideas why this might be? Anything I'm doing wrong?
Thank you!
James.