Loading...

java .net

google app engine for java:org.datanucleus.exceptions.NucleusUserException

开发中遇到这个异常:
NestedThrowablesStackTrace:
Attempt was made to manually set the id component of a Key primary key. If you want to control the value of the primary key, set the name component instead.
org.datanucleus.exceptions.NucleusUserException: Attempt was made to manually set the id component of a Key primary key. If you want to control the value of the primary key, set the name component instead.


原来的修改代码是这样些的:
public void attachDirty(UrlTarget instance) {
        PersistenceManager pm = null;
        try {
           
            pm = PMF.get().getPersistenceManager();
            UrlTarget ut = (UrlTarget) pm.getObjectById(UrlTarget.class, instance.getId());
            ut.setName(instance.getName());
            ut.setRemark(instance.getRemark());
            ut.setUrl(instance.getUrl());
           pm.makePersistent(ut);
        } catch(Exception ex){
            ex.printStackTrace();
        }finally {
            if(pm != null)pm.close();
        }
       
    }

public UrlTarget findById(Long id) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try{
            return (UrlTarget) pm.getObjectById(UrlTarget.class, id);
        }catch(Exception ex){
            ex.printStackTrace();
        }finally {
            pm.close();
        }
        return null;
    }
在利用findById方法得到对象后修改,但是findById中pm已经关闭,这就是错误的原因了

posted on 2009-10-14 18:01 阅读(398) 评论(0)  编辑  收藏 所属分类: 学习java


只有注册用户登录后才能发表评论。


网站导航:
 

公告

希望有一天

我能用鼠标双击我的钱包

然后选中一张100元

按住“ctrl+c”

接着不停的“ctrl+v”

嘻嘻~~~笑醒~~~



导航

<2009年10月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

统计

常用链接

留言簿(6)

随笔分类(102)

随笔档案(398)

文章分类

文章档案(10)

有趣网络

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜