Hi everybody,
I am trying to read a persisted object and clone this object by serializing and deserializing it. the object is part of a master-detail relation, so I don't serialize the primary keys because nhibernate should think that these objects are newly created.
the problem is as follows: serialization works, deserialization as well. but wenn i want to persist the cloned object, NHibernate throws an exception saying: NHibernate.HibernateException: Don't dereference a collection with cascade="all-delete-orphan":
The problem seems like the references to the detail-objects of my objects are still here. I need something like the Java BeanLib:
"Java Bean Library (beanlib) is a utilities library for use with JavaBean. Java Bean Library for Hibernate (beanlib-hibernate) is particularly handy when used with Hibernate. It allows developers to easily reuse the same pojo classes for both persistence instances and data transfer objects."
Any ideas appreciated!
br,
david
Hibernate version:
1.02 beta
Full stack trace of any exception that occurs:
at NHibernate.Impl.SessionImpl.PrepareCollectionForUpdate(IPersistentCollection coll, CollectionEntry entry)
at NHibernate.Impl.SessionImpl.UpdateReachableCollection(IPersistentCollection coll, IType type, Object owner)
at NHibernate.Impl.FlushVisitor.ProcessCollection(Object collection, CollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.SessionImpl.FlushEntity(Object obj, EntityEntry entry)
at NHibernate.Impl.SessionImpl.FlushEntities()
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at DataAccess.NHibernate.Daos.BaseDao`1.Save(T obj) in C:\projects\caps\sourcecontrol\Caps\CapsServer\DataAccess.NHibernate\Daos\BaseDao.cs:line 40
at Services.InMemory.Services.ProcessService.SaveProcess(Process process) in C:\projects\caps\sourcecontrol\Caps\CapsServer\Services.InMemory\Services\ProcessTemplateService.cs:line 42
at Caps.Tests.ProcessTest.TestCanCloneProcess() in C:\projects\caps\sourcecontrol\Caps\CapsServer\Caps.Tests\ProcessTest.cs:line 62
Name and version of the database you are using:
MS SQL Server 2005
The generated SQL (show_sql=true):
NHibernate: SELECT this_.ProcessId as ProcessId11_1_, this_.ProcessName as ProcessN2_11_1_, this_.Description as Descript3_11_1_, this_.Duration as Duration11_1_, this_.XCoord as XCoord11_1_, this_.YCoord as YCoord11_1_, this_.SortOrder as SortOrder11_1_, this_.StartDateTime as StartDat8_11_1_, this_.EndDateTime as EndDateT9_11_1_, this_.IsTemplate as IsTemplate11_1_, this_.ParentProcessId as ParentP11_11_1_, process2_.ProcessId as ProcessId11_0_, process2_.ProcessName as ProcessN2_11_0_, process2_.Description as Descript3_11_0_, process2_.Duration as Duration11_0_, process2_.XCoord as XCoord11_0_, process2_.YCoord as YCoord11_0_, process2_.SortOrder as SortOrder11_0_, process2_.StartDateTime as StartDat8_11_0_, process2_.EndDateTime as EndDateT9_11_0_, process2_.IsTemplate as IsTemplate11_0_, process2_.ParentProcessId as ParentP11_11_0_ FROM capsProcess this_ left outer join capsProcess process2_ on this_.ParentProcessId=process2_.ProcessId WHERE (this_.ProcessName = @p0 and this_.Duration = @p1 and this_.XCoord = @p2 and this_.YCoord = @p3 and this_.SortOrder = @p4 and this_.StartDateTime = @p5 and this_.EndDateTime = @p6 and this_.IsTemplate = @p7); @p0 = 'pr2', @p1 = '0', @p2 = '0', @p3 = '0', @p4 = '0', @p5 = '01.01.1753 00:00:00', @p6 = '01.01.1753 00:00:00', @p7 = 'False'
NHibernate: SELECT nhprofiles0_.ProcessId as ProcessId__3_, nhprofiles0_.UsedProfileId as UsedProf1_3_, nhprofiles0_.UsedProfileId as UsedProf1_8_2_, nhprofiles0_.ProfileId as ProfileId8_2_, nhprofiles0_.ProcessId as ProcessId8_2_, profile1_.ProfileId as ProfileId1_0_, profile1_.Name as Name1_0_, profile1_.ParentId as ParentId1_0_, profile2_.ProfileId as ProfileId1_1_, profile2_.Name as Name1_1_, profile2_.ParentId as ParentId1_1_ FROM capsUsedProfile nhprofiles0_ left outer join capsProfile profile1_ on nhprofiles0_.ProfileId=profile1_.ProfileId left outer join capsProfile profile2_ on profile1_.ParentId=profile2_.ProfileId WHERE nhprofiles0_.ProcessId=@p0; @p0 = '16'
NHibernate: SELECT nhpredeces0_.FollowId as FollowId__2_, nhpredeces0_.ProcessId as ProcessId2_, process1_.ProcessId as ProcessId11_0_, process1_.ProcessName as ProcessN2_11_0_, process1_.Description as Descript3_11_0_, process1_.Duration as Duration11_0_, process1_.XCoord as XCoord11_0_, process1_.YCoord as YCoord11_0_, process1_.SortOrder as SortOrder11_0_, process1_.StartDateTime as StartDat8_11_0_, process1_.EndDateTime as EndDateT9_11_0_, process1_.IsTemplate as IsTemplate11_0_, process1_.ParentProcessId as ParentP11_11_0_, process2_.ProcessId as ProcessId11_1_, process2_.ProcessName as ProcessN2_11_1_, process2_.Description as Descript3_11_1_, process2_.Duration as Duration11_1_, process2_.XCoord as XCoord11_1_, process2_.YCoord as YCoord11_1_, process2_.SortOrder as SortOrder11_1_, process2_.StartDateTime as StartDat8_11_1_, process2_.EndDateTime as EndDateT9_11_1_, process2_.IsTemplate as IsTemplate11_1_, process2_.ParentProcessId as ParentP11_11_1_ FROM capsProcessRelation nhpredeces0_ left outer join capsProcess process1_ on nhpredeces0_.ProcessId=process1_.ProcessId left outer join capsProcess process2_ on process1_.ParentProcessId=process2_.ProcessId WHERE nhpredeces0_.FollowId=@p0; @p0 = '16'
NHibernate: SELECT nhsuccesso0_.ProcessId as ProcessId__2_, nhsuccesso0_.FollowId as FollowId2_, process1_.ProcessId as ProcessId11_0_, process1_.ProcessName as ProcessN2_11_0_, process1_.Description as Descript3_11_0_, process1_.Duration as Duration11_0_, process1_.XCoord as XCoord11_0_, process1_.YCoord as YCoord11_0_, process1_.SortOrder as SortOrder11_0_, process1_.StartDateTime as StartDat8_11_0_, process1_.EndDateTime as EndDateT9_11_0_, process1_.IsTemplate as IsTemplate11_0_, process1_.ParentProcessId as ParentP11_11_0_, process2_.ProcessId as ProcessId11_1_, process2_.ProcessName as ProcessN2_11_1_, process2_.Description as Descript3_11_1_, process2_.Duration as Duration11_1_, process2_.XCoord as XCoord11_1_, process2_.YCoord as YCoord11_1_, process2_.SortOrder as SortOrder11_1_, process2_.StartDateTime as StartDat8_11_1_, process2_.EndDateTime as EndDateT9_11_1_, process2_.IsTemplate as IsTemplate11_1_, process2_.ParentProcessId as ParentP11_11_1_ FROM capsProcessRelation nhsuccesso0_ left outer join capsProcess process1_ on nhsuccesso0_.FollowId=process1_.ProcessId left outer join capsProcess process2_ on process1_.ParentProcessId=process2_.ProcessId WHERE nhsuccesso0_.ProcessId=@p0; @p0 = '16'
NHibernate: SELECT nhioproduc0_.ProcessId as ProcessId__4_, nhioproduc0_.IOProductId as IOProduc1_4_, nhioproduc0_.IOProductId as IOProduc1_0_3_, nhioproduc0_.Name as Name0_3_, nhioproduc0_.ParentId as ParentId0_3_, nhioproduc0_.ProfileId as ProfileId0_3_, nhioproduc0_.ProcessId as ProcessId0_3_, ioproduct1_.IOProductId as IOProduc1_0_0_, ioproduct1_.Name as Name0_0_, ioproduct1_.ParentId as ParentId0_0_, ioproduct1_.ProfileId as ProfileId0_0_, ioproduct1_.ProcessId as ProcessId0_0_, profile2_.ProfileId as ProfileId1_1_, profile2_.Name as Name1_1_, profile2_.ParentId as ParentId1_1_, profile3_.ProfileId as ProfileId1_2_, profile3_.Name as Name1_2_, profile3_.ParentId as ParentId1_2_ FROM capsIOProduct nhioproduc0_ left outer join capsIOProduct ioproduct1_ on nhioproduc0_.ParentId=ioproduct1_.IOProductId left outer join capsProfile profile2_ on ioproduct1_.ProfileId=profile2_.ProfileId left outer join capsProfile profile3_ on profile2_.ParentId=profile3_.ProfileId WHERE nhioproduc0_.ProcessId=@p0; @p0 = '16'
NHibernate: SELECT nhsubproce0_.ParentProcessId as ParentP11___1_, nhsubproce0_.ProcessId as ProcessId1_, nhsubproce0_.ProcessId as ProcessId11_0_, nhsubproce0_.ProcessName as ProcessN2_11_0_, nhsubproce0_.Description as Descript3_11_0_, nhsubproce0_.Duration as Duration11_0_, nhsubproce0_.XCoord as XCoord11_0_, nhsubproce0_.YCoord as YCoord11_0_, nhsubproce0_.SortOrder as SortOrder11_0_, nhsubproce0_.StartDateTime as StartDat8_11_0_, nhsubproce0_.EndDateTime as EndDateT9_11_0_, nhsubproce0_.IsTemplate as IsTemplate11_0_, nhsubproce0_.ParentProcessId as ParentP11_11_0_ FROM capsProcess nhsubproce0_ WHERE nhsubproce0_.ParentProcessId=@p0; @p0 = '16'
NHibernate: INSERT INTO capsProcess (ProcessName, Description, Duration, XCoord, YCoord, SortOrder, StartDateTime, EndDateTime, IsTemplate, ParentProcessId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9); select SCOPE_IDENTITY(); @p0 = 'pr2', @p1 = '', @p2 = '0', @p3 = '0', @p4 = '0', @p5 = '0', @p6 = '01.01.1753 00:00:00', @p7 = '01.01.1753 00:00:00', @p8 = 'False', @p9 = ''
|