异常求解?

xiao_HEIx 2014-03-27 10:03:17
Struts Problem Report

Struts has detected an unhandled exception:
Messages:

1 a different object with the same identifier value was already associated with the session: [cn.com.su.domain.Supplier#s001]
2 a different object with the same identifier value was already associated with the session: [cn.com.su.domain.Supplier#s001]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.com.su.domain.Supplier#s001]

File: org/hibernate/engine/StatefulPersistenceContext.java
Line number: 637
Stacktraces
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [cn.com.su.domain.Supplier#s001]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.com.su.domain.Supplier#s001]

org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:661)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
cn.com.su.daoimpl.MaterialDaoImpl.addMaterial(MaterialDaoImpl.java:23)
cn.com.su.serviceimpl.MaterialServiceImpl.addMaterial(MaterialServiceImpl.java:20)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy10.addMaterial(Unknown Source)
cn.com.su.action.MaterialAction.addMaterial(MaterialAction.java:55)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)





//添加材料
public String addMaterial(){

Supplier s = (Supplier) ActionContext.getContext().getSession().get("supplier");
Material material = new Material();
BeanUtils.copyProperties(getModel(), material);
Type type = typeService.searchTypeById(getModel().getMaterial_type().getId());
material.setMaterial_type(type);
Supplier supplier = supplierService.searchSupplierById(s.getSupplier_id());
material.setMaterial_supplier(supplier);
materialService.addMaterial(material);
success = true;
return "success";
}

我知道是不同的对象有相同的标识符导致的错误,但是我不明白为什么会这样,以及解决办法。
...全文
140 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧