I try to map 3 times the same table with a many-to-one relation ship.
Code:
<many-to-one name="source" class="be.nrb.dt.model.Source" column="src_id" not-null="true" cascade="none"/>
<many-to-one name="contact" class="be.nrb.dt.model.Source" column="contact_id" not-null="true" cascade="none"/>
<many-to-one name="technicalContact" class="be.nrb.dt.model.Source" column="tecContact_id" not-null="false" cascade="none"/>
I have data for src_id and contact_id. The data for tecContact_id is null (it will be filled later by another person).
I don't need to insert or update the data in the Source table. Data in source table are read-only.
I use SpringFramework 1.2.6
Error is
Could not synchronize database state with session - see full stack trace here after
What's wrong with this ?
Hibernate version: 3.1.3 Mapping documents:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="be.nrb.dt.model.Dt" table="DT_MAIN">
<id name="id" column="dtm_id" unsaved-value="null">
<generator class="increment"/>
</id>
<many-to-one name="customer" class="be.nrb.dt.model.Customer" column="cus_id" not-null="true" cascade="none"/>
<many-to-one name="status" class="be.nrb.dt.model.Status" column="sta_id" not-null="true" cascade="none"/>
<many-to-one name="source" class="be.nrb.dt.model.Source" column="src_id" not-null="true" cascade="none"/>
<many-to-one name="contact" class="be.nrb.dt.model.Source" column="contact_id" not-null="true" cascade="none"/>
<many-to-one name="technicalContact" class="be.nrb.dt.model.Source" column="tecContact_id" not-null="false" cascade="none"/>
<many-to-one name="drLevel" class="be.nrb.dt.model.DrLevel" column="drl_id" not-null="true" cascade="none"/>
<property name="cd" column="dtm_cd" type="string" not-null="true" length="10"/>
<property name="name" column="dtm_name" type="string" not-null="true" length="300"/>
<property name="orderDate" column="dtm_orderDate" type="java.util.Date" not-null="true"/>
<property name="projectRef" column="dtm_projectRef" type="string" not-null="true" length="15"/>
<property name="description" column="dtm_description" type="string" not-null="true" length="300"/>
<property name="dlDevis" column="dtm_dlDevis" type="java.util.Date" not-null="true"/>
<property name="dlInfra" column="dtm_dlInfra" type="java.util.Date" not-null="true"/>
<property name="maxEstimatedCost" column="dtm_maxEstimatedCost" type="long" not-null="true" length="15"/>
<property name="drLevelDir" column="dtm_drLevelDir" type="string" not-null="false" length="300"/>
<property name="drLevelFile" column="dtm_drLevelFile" type="string" not-null="false" length="50"/>
<property name="reporting" column="dtm_reporting" type="string" not-null="true" length="1"/>
<property name="reportingDir" column="dtm_reportingDir" type="string" not-null="false" length="300"/>
<property name="reportingFile" column="dtm_reportingFile" type="string" not-null="false" length="50"/>
<property name="existingInfra" column="dtm_existingInfra" type="string" not-null="true" length="1"/>
<property name="existingInfraDir" column="dtm_existingInfraDir" type="string" not-null="false" length="300"/>
<property name="existingInfraFile" column="dtm_existingInfraFile" type="string" not-null="false" length="50"/>
<property name="sla" column="dtm_sla" type="string" not-null="true" length="1"/>
<property name="slaDir" column="dtm_slaDir" type="string" not-null="false" length="300"/>
<property name="slaFile" column="dtm_slaFile" type="string" not-null="false" length="50"/>
<property name="bs" column="dtm_bs" type="string" not-null="true" length="1"/>
<property name="bsDir" column="dtm_bsDir" type="string" not-null="false" length="300"/>
<property name="bsFile" column="dtm_bsFile" type="string" not-null="false" length="50"/>
<property name="releaseDate" column="dtm_releaseDate" type="java.util.Date" not-null="false"/>
<property name="version" column="dtm_version" type="long" not-null="true" length="5"/>
<property name="globalCost" column="dtm_globalCost" type="long" not-null="false" length="15"/>
<property name="architecturFlag" column="dtm_architecturFlag" type="string" not-null="false" length="1"/>
<property name="architecturDir" column="dtm_architecturDir" type="string" not-null="false" length="300"/>
<property name="architecturFile" column="dtm_architecturFile" type="string" not-null="false" length="50"/>
<property name="estimateFlag" column="dtm_estimateFlag" type="string" not-null="false" length="1"/>
<property name="estimateDir" column="dtm_estimateDir" type="string" not-null="false" length="300"/>
<property name="estimateFile" column="dtm_estimateFile" type="string" not-null="false" length="50"/>
<property name="longDescription" column="dtm_longDescription" type="string" not-null="false" length="1000"/>
<property name="swSetupCost" column="dtm_sw_setupCost" type="double" not-null="false" precision="15" scale="2"/>
<property name="swRecuCost" column="dtm_sw_recuCost" type="double" not-null="false" precision="15" scale="2"/>
<property name="hwSetupCost" column="dtm_hw_setupCost" type="double" not-null="false" precision="15" scale="2"/>
<property name="hwRecuCost" column="dtm_hw_recuCost" type="double" not-null="false" precision="15" scale="2"/>
<list name="serviceItems" inverse="true" cascade="all-delete-orphan">
<key column="dtm_id" not-null="false"/>
<index column="svi_id"/>
<one-to-many class="be.nrb.dt.model.ServiceItem"/>
</list>
<list name="stdCostItems" inverse="true" cascade="all-delete-orphan">
<key column="dtm_id" not-null="false"/>
<index column="sci_id"/>
<one-to-many class="be.nrb.dt.model.StdCostItem"/>
</list>
<property name="act" column="dtm_act" type="string" not-null="true" length="1"/>
<property name="dencod" column="dtm_dencod" type="java.util.Date" not-null="true"/>
<property name="signed" column="dtm_signed" type="long" not-null="true" length="15"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): Code:
public void save(final Dt argDt) {
if (log.isDebugEnabled()) {
log.debug("save(...)");
log.debug("dtId [" + argDt.getId() + "]");
log.debug("argDt.getContact().getId() [" + argDt.getContact().getId() + "]");
log.debug("argDt.getSource().getId() [" + argDt.getSource().getId() + "]");
}
// getHibernateTemplate().merge(argDt);
getHibernateTemplate().saveOrUpdate(argDt);
}
Full stack trace of any exception that occurs:
DEBUG - DtDAOHibernate.save(85) | save(...)
DEBUG - DtDAOHibernate.save(86) | dtId [8]
DEBUG - DtDAOHibernate.save(87) | argDt.getContact().getId() [8]
DEBUG - DtDAOHibernate.save(88) | argDt.getSource().getId() [9]
Hibernate: update DT_MAIN set cus_id=?, sta_id=?, src_id=?, contact_id=?, tecContact_id=?, drl_id=?, dtm_cd=?, dtm_name=?, dtm_orderDate=?, dtm_projectRef=?, dtm_description=?, dtm_dlDevis=?, dtm_dlInfra=?, dtm_maxEstimatedCost=?, dtm_drLevelDir=?, dtm_drLevelFile=?, dtm_reporting=?, dtm_reportingDir=?, dtm_reportingFile=?, dtm_existingInfra=?, dtm_existingInfraDir=?, dtm_existingInfraFile=?, dtm_sla=?, dtm_slaDir=?, dtm_slaFile=?, dtm_bs=?, dtm_bsDir=?, dtm_bsFile=?, dtm_releaseDate=?, dtm_version=?, dtm_globalCost=?, dtm_architecturFlag=?, dtm_architecturDir=?, dtm_architecturFile=?, dtm_estimateFlag=?, dtm_estimateDir=?, dtm_estimateFile=?, dtm_longDescription=?, dtm_sw_setupCost=?, dtm_sw_recuCost=?, dtm_hw_setupCost=?, dtm_hw_recuCost=?, dtm_act=?, dtm_dencod=?, dtm_signed=? where dtm_id=?
ERROR - AbstractFlushingEventListener.performExecutions(300) |
Could not synchronize database state with session
org.hibernate.TransientObjectException: be.nrb.dt.model.Source
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2172)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:496)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:469)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:266)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy1.save(Unknown Source)
at be.nrb.dt.web.DtFormBean.save(DtFormBean.java:443)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:97)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:97)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
ERROR - StandardWrapperValve.invoke(253) | "Servlet.service()" pour la servlet FacesServlet a généré une exception
javax.faces.FacesException: Error calling action method of component with id dtForm:showSaveBtn:save-button
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:97)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:97)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{dtFormBean.save}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
... 33 more
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: be.nrb.dt.model.Source; nested exception is org.hibernate.TransientObjectException: be.nrb.dt.model.Source
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:658)
at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:715)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:592)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:496)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:469)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:266)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy1.save(Unknown Source)
at be.nrb.dt.web.DtFormBean.save(DtFormBean.java:443)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
... 34 more
Caused by: org.hibernate.TransientObjectException: be.nrb.dt.model.Source
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2172)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
... 47 more
Name and version of the database you are using:
Oracle XE
The generated SQL (show_sql=true):
update DT_MAIN set cus_id=?, sta_id=?, src_id=?, contact_id=?, tecContact_id=?, drl_id=?, dtm_cd=?, dtm_name=?, dtm_orderDate=?, dtm_projectRef=?, dtm_description=?, dtm_dlDevis=?, dtm_dlInfra=?, dtm_maxEstimatedCost=?, dtm_drLevelDir=?, dtm_drLevelFile=?, dtm_reporting=?, dtm_reportingDir=?, dtm_reportingFile=?, dtm_existingInfra=?, dtm_existingInfraDir=?, dtm_existingInfraFile=?, dtm_sla=?, dtm_slaDir=?, dtm_slaFile=?, dtm_bs=?, dtm_bsDir=?, dtm_bsFile=?, dtm_releaseDate=?, dtm_version=?, dtm_globalCost=?, dtm_architecturFlag=?, dtm_architecturDir=?, dtm_architecturFile=?, dtm_estimateFlag=?, dtm_estimateDir=?, dtm_estimateFile=?, dtm_longDescription=?, dtm_sw_setupCost=?, dtm_sw_recuCost=?, dtm_hw_setupCost=?, dtm_hw_recuCost=?, dtm_act=?, dtm_dencod=?, dtm_signed=? where dtm_id=?
Debug level Hibernate log excerpt: