after doing research on web found fact hibernate has bug> hibernate let's disappear cause of exceptions or ;ike makes me unable solve exception.
so have object try update hibernate merge() method. (persist work correctly)
i had problem few times before in project , solutions don't work found before.
i found similar question answers them property norollbackfor=exception.class
in @transactional
. want prevent doing in code plus doesn't work in case.
database using: mysql
object try update:
@entity @table(name = "applications", uniqueconstraints = @uniqueconstraint(columnnames = { "name", "customer_id" }) ) public class applicationinfo extends domainobject { private static final long serialversionuid = -5112065902722692463l; @id @generatedvalue(strategy=generationtype.identity) private long id; @notnull @notblank private string name; @manytoone(cascade = cascadetype.merge) @joincolumn(name = "customer_id", nullable = false) private customer customer; @column(name = "group_id") private string groupid; @notnull @notblank @column(name = "artifact_id") private string artifactid; @notnull @notblank @column(name = "type") private string type; @column(name = "deployment_group_id") private string deploymentgroupid; @notnull @column(name = "deployment_artifact_id") private string deploymentartifactid; @column(name = "app_nodes") @onetomany(fetch = fetchtype.lazy, cascade = cascadetype.all, mappedby = "application") @lazycollection(lazycollectionoption.false) private set<applicationnode> applicationnodes; @onetomany(cascade = cascadetype.all, mappedby = "application") @orderby("sortkey asc") @lazycollection(lazycollectionoption.false) private list<stage> stages; @onetomany(cascade = cascadetype.all, mappedby = "application") @lazycollection(lazycollectionoption.false) private list<applicationproperty> properties; @manytoone(cascade = cascadetype.merge) @joincolumn(name = "nexus_info_id", nullable = true) private nexusinfo nexusinfo; // getters , setters
the save methoid:
@override @transactional(propagation = propagation.required) public t save(t t) { try { if (t.getid() == null) { getentitymanager().persist(t); } else { t = getentitymanager().merge(t); } return t; } catch (exception e) { log.error(e); } return t; }
correct me if mussing / ask me if need more information.
domainobject:
public abstract class domainobject implements serializable, comparable<domainobject> { private static final long serialversionuid = -2606953921071135629l; public abstract long getid(); public abstract void setid(long id); @override public int hashcode() { if (getid() != null) { return getid().hashcode(); } else { return this.getclass().getcanonicalname().hashcode(); } } public boolean equals(object obj) { if (obj == this) { return true; } if (obj instanceof domainobject) { domainobject dobj = (domainobject) obj; if (this.getid() != null) { return this.getid().equals(dobj.getid()); } } return false; } public int compareto(domainobject obj) { if (obj != null) { if (this.getid() != null && obj.getid() != null) { return this.getid().compareto(obj.getid()); } } return 0; } }
the exception: can ignore references applicationcontroller, calls safe method
2016-01-29 13:16:03 error applicationscontroller:58 - java.lang.illegalstateexception: multiple representations of same entity [nl.ciber.deploy.metadata.model.applicationinfo#1] being merged. detached: [applicationinfo[id=1,name=mds,customer=nl.ciber.deploy.metadata.model.customer@603bdce,groupid=-,artifactid=-,type=-,deploymentgroupid=-,deploymentartifactid=-,applicationnodes=[],stages=[],properties=[],nexusinfo=<null>]]; detached: [applicationinfo[id=1,name=mds,customer=nl.ciber.deploy.metadata.model.customer@603bdce,groupid=-,artifactid=-,type=-,deploymentgroupid=-,deploymentartifactid=-,applicationnodes=<null>,stages=<null>,properties=<null>,nexusinfo=<null>]] jan 29, 2016 1:16:03 pm org.apache.catalina.core.standardwrappervalve invoke severe: servlet.service() servlet [spring] in context path [/mds] threw exception [request processing failed; nested exception org.springframework.transaction.transactionsystemexception: not commit jpa transaction; nested exception javax.persistence.rollbackexception: transaction marked rollbackonly] root cause javax.persistence.rollbackexception: transaction marked rollbackonly @ org.hibernate.ejb.transactionimpl.commit(transactionimpl.java:72) @ org.springframework.orm.jpa.jpatransactionmanager.docommit(jpatransactionmanager.java:517) @ org.springframework.transaction.support.abstractplatformtransactionmanager.processcommit(abstractplatformtransactionmanager.java:757) @ org.springframework.transaction.support.abstractplatformtransactionmanager.commit(abstractplatformtransactionmanager.java:726) @ org.springframework.transaction.interceptor.transactionaspectsupport.committransactionafterreturning(transactionaspectsupport.java:521) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:291) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:96) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ com.sun.proxy.$proxy44.saveapplication(unknown source) @ nl.ciber.deploy.metadata.controller.applicationscontroller.editapp(applicationscontroller.java:150) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:137) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:777) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:706) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:943) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:877) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:868) @ javax.servlet.http.httpservlet.service(httpservlet.java:648) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:118) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:84) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:113) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:103) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:113) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:154) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:45) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.www.basicauthenticationfilter.dofilter(basicauthenticationfilter.java:150) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:199) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:110) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:50) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:87) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:192) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:160) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:344) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:261) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:142) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:616) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:518) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1091) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:673) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1526) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1482) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source)
thank in advance time.
Comments
Post a Comment