Results 1 to 4 of 4

Thread: Second createOrUpdate fails

  1. #1

    Default Second createOrUpdate fails

    Hi there,

    I'm currently working on a project that's using spring 2.0.4, webflow 1.0.3 and hibernate 3.2.4.sp1.

    Here is my action method of webflow that throws an exception. It looks like a really simple statement, but I'm unable to reproduce the same error in a JUNIT test.


    Code:
        public Event bindReportingAndSave(final RequestContext context) throws Exception {
            Reporting reporting  = assignmentService.findReportingById(29L);  
            assignmentService.createOrUpdate(reporting);
       }
    It throws following exception:

    Code:
    Exception:
    org.springframework.webflow.engine.ActionExecutionException: Exception thrown executing [AnnotatedAction@1596170 targetAction = xxx.web.assignment.action.AssignmentActions@1d5b1dc, attributes = map['method' -> 'bindReportingAndSave']] in state 'assignment-generalReportingView' of flow 'assignments-flow' -- action execution attributes were 'map['method' -> 'bindReportingAndSave']'; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: Found two representations of same collection: xxx.domain.assignments.Assignment.contacts; nested exception is org.hibernate.HibernateException: Found two representations of same collection: xxx.domain.assignments.Assignment.contacts
    Caused by: org.springframework.orm.hibernate3.HibernateSystemException: Found two representations of same collection: xxx.domain.assignments.Assignment.contacts; nested exception is org.hibernate.HibernateException: Found two representations of same collection: xxx.domain.assignments.Assignment.contacts
    Caused by: org.hibernate.HibernateException: Found two representations of same collection: xxx.domain.assignments.Assignment.contacts
    	at org.hibernate.engine.Collections.processReachableCollection(Collections.java:153)
    	at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
    	at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
    	at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
    	at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
    	at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:131)
    	at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
    	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:126)
    	at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:824)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:634)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:621)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:311)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:203)
    	at $Proxy93.createOrUpdate(Unknown Source)
    	at xxx.web.assignment.action.AssignmentActions.bindReportingAndSave(AssignmentActions.java:514)
    Here is my configuration:

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="xxx.assignments">
    	<class name="Assignment" schema="XXX" table="OPDRACHT">
    		<id column="ID" name="id" type="long" unsaved-value="null">
    			<generator class="native" />
    		</id>
            <discriminator column="DISCRIMINATOR" type="string"/>
    	
    		<property name="objectName" column="NAAM"/>
    		<property name="reference" column="REFERENTIE"/>
    		<property name="registrationDate" type="date" column="REGISTRATIE_D"/>
    		<property name="referenceCustomer" column="REFERENTIE_OPDRACHTGEVER"/>
    		<property name="comments" column="COMMENTAAR"/>
    		<property name="evaluation" column="BEOORDELINGSCOMMENTAAR"/>
    		<property name="temporary" column="VOORLOPIG_B" type="jnBoolean"/>
    		<property name="urgency" column="URGENTIE"/>
    		<many-to-one name="address" class="xxx.domain.commons.Address" column="ADRES_ID" />
            <many-to-one name="assignmentType" class="xxx.domain.commons.AssignmentType" column="OPDRACHT_TYPE_ID" lazy="false"/>
    
    		<set name="contacts" schema="XXX" table="OPDRACHT_CONTACTPERSOON" access="field">
    			<key column="OPDRACHT_ID"/>
    			<many-to-many class="xxx.domain.customer.Customer" column="KLANT_ID"/>
    		</set>
            
            <set name="customers" schema="XXX" table="OPDRACHT_KLANT"  access="field">
                <key column="OPDRACHT_ID"/>
                <many-to-many class="xxx.domain.customer.Customer" column="KLANT_ID" />
            </set>
    		
            <set name="files" schema="XXX" table="DOSSIER_OPDRACHT" access="field">
                <key column="OPDRACHT_ID"/>
                <many-to-many class="xxx.domain.assignments.File" column="DOSSIER_ID" />
            </set>
            
            <set name="documents" schema="XXX" table="OPDRACHT_DOCUMENT" access="field">
                <key column="OPDRACHT_ID"/>
                <many-to-many class="xxx.domain.commons.Document" column="DOCUMENT_ID"/>
            </set>
            
            <!-- Subclass by discriminator. -->
            <subclass name="Reporting" discriminator-value="melding">
    
                <property name="reportDate" type="date" column="RAPPORT_D"/>
                <many-to-one name="reportingType" class="xxx.domain.assignments.ReportingType" column="MELDING_TYPE_ID" lazy="false"/>
    
                <set name="informants" table="OPDRACHT_MELDER" schema="XXX" access="field" lazy="false">
                    <key column="OPDRACHT_ID" />
                    <composite-element class="xxx.domain.assignments.AssignmentInformantContactHolder">
                        <parent name="assignment" />
                        <many-to-one name="customer" column="MELDER_ID" class="xxx.domain.customer.Customer" access="field"/>
                        <many-to-one name="contact" column="CONTACT_ID" class="xxx.domain.customer.Customer" access="field"/>
                    </composite-element>
                </set>
    
                <many-to-one name="reportingForm" class="xxx.domain.commons.Document" 
                    column="RAPPORT_DOCUMENT_ID"/>
    
                <property name="capacity" type="string" column="CAPACITEIT"/>
                <property name="parcelListAttachment" type="jnBoolean" column="PERCEELLIJST_B"/>
                <property name="cadastralMapAttachment" type="jnBoolean" column="KADASTERMAP_B"/>            
                <property name="ledgerAttachment" type="jnBoolean" column="GROOTBOEK_B"/>            
                <property name="agreementAttachment" type="jnBoolean" column="AKKOORD_B"/>                        
    			<property name="authorizationAttachment" type="jnBoolean" column="AUTHORISATIE_B"/>            
                <property name="oboAttachment" type="jnBoolean" column="OBO_B"/>  
                
            </subclass>
            
            <subclass name="Examination" discriminator-value="onderzoek">
            
            </subclass>
    	</class>
    </hibernate-mapping>
    As you can see in above, I'm using a discriminator and composite-element setup.

    Further setup:
    Code:
        <bean id="assignmentService"
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
            abstract="false" lazy-init="default" autowire="default"
            dependency-check="default">
            <property name="transactionManager" ref="txManager" />
            <property name="target" ref="assignmentServiceTarget" />
            <property name="transactionAttributes">
                <props>
                    <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
                </props>
            </property>
        </bean>
        
        <bean id="assignmentServiceTarget"
            class="xxx.assignments.service.AssignmentServiceImpl">
            <property name="assignmentDao">
                <ref bean="assignmentDao" />
            </property>
        </bean>
    My Domain model classes are pretty straightforward. Can't post them since the post is limited in size.

    Reporting extends Assignment.
    Only Getters and Setters are being used.
    If needed I'll post them.


    I'm looking at the code for quite a while. Any suggestions or fresh idea's what the problem might be are very appreciated.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Can you post your unit test? I figure it has to do with the way your transactions are setup. The transactions are around the service layer methods (which is good and which is where they belong). However you are calling 2 service methods, resulting in 2 transactions, which might cause trouble if you are trying to do some reloading down the line.

    If you use the testclasses with Spring your whole testmethod is wrapped in 1 transaction and your service calls participate in this transaction.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    My testclasses are nothing special.
    I have an AbstractTransactionDependencyInjectionTests, with DBUnit injecting testData and stuff.

    The service calls are exactly as the action calls.

    Indeed, my testCase is 1 transaction.

    Why would this has anything to do with transactions? (Trying to understand the true problem.)

    I'll write a testCase that controls the transaction behavior itself.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I'd try having a search for the exception; "HibernateException: Found two representations of same collection". It seems there are lots of exist posts out there.
    Last edited by karldmoore; Aug 29th, 2007 at 12:08 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •