小编GSA*_*SAN的帖子

hibernate NonUniqueObjectException:具有相同标识符值的其他对象已与会话关联:

我的代码:

我正在尝试更新/插入.它被正确插入,唯一的问题是当我尝试更新它时给出了以下错误消息.

private String sessionType=null;
public String getAccountsDetails(List<Account> accountList) {       
    Session session = sessionFactory.openSession();
    for (Account account : accountList) {
        AccountDetails accountDetails = new AccountDetails();
        accountDetails.setAccountsId(Long.parseLong(account.getId()));
        accountDetails.setAccounttype(account.getAccountType().value());
        Query query = session.createQuery("from QBAccounts qba where qba.accountsId=:accId");
        List<AccountDetails> queryList = query.setParameter("accId", accountDetails.getAccountsId()).list();
        if(queryList.size()>0){         
            session.update(accountDetails);
        }else{
            session.save(accountDetails);
        }
    }
    session.flush();  
    session.beginTransaction().commit();
    session.clear();
    session.close();           
    return "Successfully data updated into table";
}
Run Code Online (Sandbox Code Playgroud)

错误:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.trinet.mulesoft.quickbooks.dto.AccountDetails#0]
    at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:638)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:305)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:246) …
Run Code Online (Sandbox Code Playgroud)

hibernate hibernate-mapping

11
推荐指数
2
解决办法
5万
查看次数

[method]操作接受未使用@Validateable标记的[org ... JSONObject]类型的参数。

我收到此警告:

Warning |The [addPeople] action accepts a parameter of type [org.codehaus.groovy.grails.web.json.JSONObject] which has not been marked with @Validateable.  Data binding will still be applied to this command object but the instance will not be validateable.

   def addPeople(JSONObject jsonsito) {
Run Code Online (Sandbox Code Playgroud)

如果我将JSONObject更改为def,则警告消失。我确定引用是JSONObject。我这样做是为了避免将来出现PermGem错误。

任何人都可以解释如何用@Validateable标记此OBJ?

提前致谢。

grails groovy warnings

3
推荐指数
1
解决办法
758
查看次数

标签 统计

grails ×1

groovy ×1

hibernate ×1

hibernate-mapping ×1

warnings ×1