DuplicateKeyException Hibernate 3版本在saveorUpdate上更新

时间:2019-02-22 14:01:06

标签: java hibernate spring-orm

将休眠版本从3.3.1GA更新到3.6.10.Final

时发生此错误

我正在更新一个应用程序(JSP + spring 4.2 + hibernate + java 8),在其中我需要执行编辑和添加功能,并将结果存储到两个表中,例如PriceSchedule和PriceScheduleItem。两者之间的关系是多对一的。 在我的父hbm文件中,我通过一对多(子类字段)启用了 cascade =“ all”

我正在从数据库获取数据,并在编辑记录时,如果我不更改(在JSP中)任何字段值,那么它将引发如下异常。

org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was already associated with the session: [com.pstechnology.domain.PriceSchedule#124]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.pstechnology.domain.PriceSchedule#124]
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:678)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:416)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:416)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:379)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:782)
    at com.pstechnology.persistence.spring.dao.BaseDAOImpl.saveOrUpdate(BaseDAOImpl.java:81)
    at com.pstechnology.service.BaseService.saveOrUpdate(BaseService.java:55)
    at com.pstechnology.service.BaseService$$FastClassBySpringCGLIB$$61ce2679.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
    at com.pstechnology.logging.ServiceMethodProfiler.profile(ServiceMethodProfiler.java:27)
    at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

如果我更改任何字段值,则说明保存成功。

Am使用命令对象从JSP获取信息。 有人可以指导我解决此错误。

仅供参考: 1)通过将其设置为VO对象,将休眠域对象发送到JSP。 2)我无法再更新休眠版本,公司maven repo没有最新的休眠版本,管理层也不想在这些上花费很多时间。

0 个答案:

没有答案