Thread:
 Does it really work ? 
 grucha   08 Feb 2005, 04:54 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: grucha (08 Feb 2005, 04:54) Replies: 0, Views: 37858
Subject: Does it really work ?
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 ?
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]