These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Composite-Element not being saved on cascade
PostPosted: Tue Apr 22, 2008 7:23 am 
Newbie

Joined: Tue Apr 22, 2008 7:17 am
Posts: 14
Hi,

I'm having a problem with a collection of composite-elements that I've defined. They don't seem to be saving properly. My mapping is as follows:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                  assembly="OzoneHR.Domain"
                  namespace="OzoneHR.Domain.Questionnaires">
  <class name="QuestionTemplate" table="QuestionTemplate">
    <id name="Id" access="nosetter.camelcase-underscore"
        column="QuestionTemplateID" type="Int32">
      <generator class="identity" />
    </id>
    <property name="QuestionText" column="QuestionText" type="String" not-null="true" access="nosetter.camelcase-underscore" />   
    <bag name="SubDomains"
         table="QuestionTemplateInSubdomain"
         cascade="all"
         access="nosetter.camelcase-underscore"
         >
      <key column="QuestionTemplateID" />     
      <composite-element class="QuestionnaireSubdomain">       
        <property name="SubdomainName" access="nosetter.camelcase-underscore" column="Subdomain" not-null="true" />         
      </composite-element>     
    </bag>
    <bag name="Domains"
         table="QuestionTemplateInDomain"
         cascade="all"
         access="nosetter.camelcase-underscore"
         >
      <key column="QuestionTemplateID" />
      <composite-element class="QuestionnaireDomain">
        <property name="DomainName" access="nosetter.camelcase-underscore" column="Domain" not-null="true" />       
      </composite-element>
    </bag>
  </class>
</hibernate-mapping>


Neither the Subdomains or Domains collections are being persisted as expected.

There is a slight caveat there, in that in my test of this code, if I explicitly call Commit on the current transaction, the cascading inserts are generated, but if I don't only the insert for the parent object is generated. E.g:

Code:
QuestionTemplate template = new QuestionTemplate(templateText, subdomain, domain);
sessManager.OpenSession().Transaction.Begin();

IRepository<QuestionTemplate, int> repository = IoC.Resolve<IRepository<QuestionTemplate, int>>();
repository.Save(template);


This code only generates a commit for the parent QuestionTemplate object. By adding:

Code:
sessManager.OpenSession().Transaction.Commit()


the additional child commits are generated.

Anyone have any ideas?

Thanks,
Matt


Top
 Profile  
 
 Post subject: Composite-Element not being saved on cascade
PostPosted: Tue Apr 22, 2008 8:31 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Matt,

Quote:
if I explicitly call Commit on the current transaction, the cascading inserts are generated


I think that is correct behaviour. The unit-of-work will leave as much as possible of the DB calls until the last possible moment.

If you want to see the unit-of-work contents written to disk before the transaction is committed, you could try:

Code:
sessManager.OpenSession().Flush();


Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 9:01 am 
Newbie

Joined: Tue Apr 22, 2008 7:17 am
Posts: 14
Ah, right, thanks very much Richard!

Calling Flush() fixes it.

Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.