我的代码:
我正在尝试更新/插入.它被正确插入,唯一的问题是当我尝试更新它时给出了以下错误消息.
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) 我收到此警告:
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?
提前致谢。