开发者

Google App Engine error Object Manager has been closed

I had following error from Google App Engine when I was trying to iterate list in JSP page with EL.

Object Manager has been closed

I solved problem with following code, but I don't think that it is very good solution to this problem:

public List<Item> getItems() {
        PersistenceManager pm = getPersistenceManager();
        Query query = pm.newQuery("select from " + Item.class.getName());
        List<Item> items = (List<Items>) 开发者_JAVA百科query.execute();       
        List<Item> items2 = new ArrayList<Item>(); // This line solved my problem 
        Collections.copy(items, items2); // and this also 
        pm.close();
        return (List<Item>) items;
    }

When I tried to use pm.detachCopyAll(items) it gave same error. I understood that detachCopyAll() method should do same what I did, but that method should be part of data nucelus, so it should be used instead of my owm methods. So why dosen't detachCopyAll() work at all?


I solved this myself. I didn't had @PersistenceCapable(detachable="true") at my entity, so apparently objects aren't detachable by deafult.

@PersistenceCapable(detachable="true")
public class Item {

...

}


I'm getting this error too...

You can call method size() of your list before calling close(); I think it's a bug no fixed yet, because in other JPA implementations the same code doesn't throw any exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜