I used this solution, and received exception:
"net.sf.hibernate.LazyInitializationException: cannot access loading
collection"
inside getIndex(). I looked into Hibernate sources. During
initialization of collection, every element is initialized. After
initialization of single element it is inserted into second level
cache. ChacheEntry class then invokes persister.getPropertyValues
(object). And here is the problem. getIndex() is invoked (through
getPropertyValues) befor collection is initialized. There is solution
to this problem, but very, very ugly.
public int getIndex()
{
try {
return getParent().getChildren().indexOf(this);
}
catch (Exception e) {
return indexFromSet;
}
}
int indexFromSet;
private void setIndex(int index)
{
indexFromSet = index;
}
This is ugly hack, and should not be used. Any better ideas ? |