-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need to cascade on first save only (and not on next updates)
PostPosted: Tue Jun 20, 2006 7:19 am 
Newbie

Joined: Tue Jun 20, 2006 6:54 am
Posts: 3
Hibernate version:

0.8.6

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Horizons.BPM.ProcessModel.ProcessDefinition, Horizons.BPM"
table="ProcessDefinition">

<id name="ID" column="ID" access="nosetter.lowercase-underscore" unsaved-value="0">
<generator class="native" />
</id>

<property name="ModelID" column="ModelID" type="string" />
<property name="Name" column= "Name" type="string"/>
<property name="Version" column= "Version"/>
<property name="Description" column= "Description" type="string"/>
<property name="Duration" column= "Duration"/>
<property name="Deviation" column= "Deviation"/>
<property name="MaxScale" column= "MaxScale"/>
<property name="MinScale" column= "MinScale"/>
<property name="DurationUnit" column="DurationUnit" type="Horizons.BPM.DurationUnit, Horizons.BPM"/>
<property name="Author" column= "Author" type="string"/>
<property name="CreationDate" column="creationDate" type="DateTime"/>
<property name="State" column="State" type="Horizons.BPM.ProcessDefinitionState, Horizons.BPM"/>

<many-to-one name="ParentPackage" column="ParentPackage" not-null="true"/>


<many-to-one name="FirstActivity" access="property"
class="Horizons.BPM.ProcessModel.ActivityType.ActivityDefinition, Horizons.BPM"
column="FirstActivity"
cascade="save-update"/>

<set name="Activities" cascade="all" lazy="false" access="property" inverse="true">
<key column="ParentProcessID"/>
<one-to-many class="Horizons.BPM.ProcessModel.ActivityType.ActivityDefinition, Horizons.BPM"/>
</set>


Name and version of the database you are using:

MSSQL server 2005

My question is :

ProcessDefinition contains a set of ActivityDefinitions. One of these activities is a refered to as FirstActivity.

The problem is that when the ProcessDefinition first saves, every thing is ok. But when it updates, it gives the following error:

-----------------------------------------------------------------
UnitTests.ProcessModel.ActivityType.SubflowActivityTest.TestTransitionLogic : System.Exception : Exception in ActivateProcess
----> Horizons.BPM.DataAccess.DataAccessException : Can't save/update object.
----> NHibernate.ADOException : Could not save object
----> NHibernate.HibernateException : another object with the same id was already associated with the session: [ActivityDefinition#112]
...
...
--at DataAccessException
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at Horizons.BPM.ProcessModel.DataAccess.ProcessDefinitionDA.Save(ProcessDefinition BusinessObject) in D:\vss\PA\Version 2.0 Maintenance\Code\Horizons.BPM\Horizons.BPM\ProcessModel\DataAccess\ProcessDefinitionDA.cs:line 179
--ADOException
at NHibernate.Impl.SessionImpl.CheckUniqueness(Key key, Object obj)
at NHibernate.Impl.SessionImpl.DoUpdateMutable(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.DoUpdate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at NHibernate.Engine.Cascades.CascadingAction.ActionSaveUpdateClass.Cascade(ISessionImplementor session, Object child, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IClassPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)

----------------------------------------------------------------

If I set the cascade=none, then the reference to the FirstActivity is not saved at all.

What I need is a feature like cascade="create", which is available in the Java Hibernate long time ago.

Is there any workaround for this? Please help !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 11:21 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you can simply set the cascade to "save" (cascade="save"), but i think you are avoiding another problem related to how your objects are mapped.

also, you really need to update to at least NH 1.0.2.0, too. many, many bugs have been fixed since 0.8.6...

-devon


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.