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: Cant get more than one many-to-many mapping to work.
PostPosted: Wed Apr 11, 2007 1:32 am 
Newbie

Joined: Wed Apr 11, 2007 12:24 am
Posts: 3
Location: Melbourne
Hi,

I've got a strange problem with NHibernate version 1.2.0.3001

I have a class mapping with two many to many bag collection mappings.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="BizObjects.WindowTypes.WindowEditPolicy, BizObjects" table="WindowEditPolicies">
    <id name ="DbId" column="wepId" type="Int64" unsaved-value="0">
      <generator class="identity"/>
    </id>
    <property name ="Timestamp" column="wepTimestamp" type="DateTime"/>
    <property name ="Name" column="wepName" type="String"/>

    <bag name ="AllowedFrames" table="wepAllowedFramesList" inverse="false" cascade="all">
      <key column ="frmWindowEditPolicyId" />
      <many-to-many column="FrameTypeId" class ="BizObjects.FrameType.GenericFrameType, BizObjects"/>
    </bag>
       
    <bag name ="AllowedGlasses" table="wepAllowedGlassesList" inverse="false" cascade="all">
      <key column ="glsWindowEditPolicyId" />
      <many-to-many column="GlassTypeId" class ="BizObjects.GlassType.GenericGlassType, BizObjects"/>
    </bag>
   
  </class>
</hibernate-mapping>


The code goes like this (between session/transaction start and end):

Code:
            WindowEditPolicy wep = new WindowEditPolicy()

            GenericFrameType frm = new GenericFrameType();
            GenericFrameType frm2 = new GenericFrameType();

            GenericGlassType gls = new GenericGlassType();
            GenericGlassType gls2 =new GenericGlassType();
           
            wep.AllowedFrames.Add(frm);
            wep.AllowedFrames.Add(frm2);
           
            wep.AllowedGlasses.Add(gls);
            wep.AllowedGlasses.Add(gls2);           
            session.Save(wep);



When I run a test that executes the code above I get an exception:

Code:
DataObjectsTest.TestWindowEditPolicyWriteAndRead.TestWriteWindowEditPolicy : NHibernate.ADOException : could not insert collection: [BizObjects.WindowTypes.WindowEditPolicy.AllowedFrames#1]
  ----> System.Data.OleDb.OleDbException : You cannot add or change a record because a related record is required in table 'FrameTypes'.


Now the strange part....

When I remove the following lines from the mapping file (that is, I only persist one of the collections, rather than two, without changing any other code):
Code:
    <bag name ="AllowedGlasses" table="wepAllowedGlassesList" inverse="false" cascade="all">
      <key column ="glsWindowEditPolicyId" />
      <many-to-many column="GlassTypeId" class ="BizObjects.GlassType.GenericGlassType, BizObjects"/>
    </bag>


It all seems to work correctly for the collection that is still in the mapping file (ie the AllowedFrames).

It appears to me that hibernate is getting confused between the two collections when there are more than one in the class. I have searched forums/tutorials etc which all give examples with a single many to many mapping....

I have followed these and they seem to work, however when a second collection is added it falls over. To me, removing the mapping for the "Allowed Glasses", should not fix an error for "Allowed Frames". I think that this looks like a hibernate bug.

Now another strange one....

If I leave both mappings in (back to the original situation with the exception)...

And then I remove the following lines from the code:

Code:
            wep.AllowedGlasses.Add(gls);
            wep.AllowedGlasses.Add(gls2); 


That is, I dont add any elements to the second mapping...There is no exception, however nothing has been saved to the database.

Very confusing. Argghgh

Has anyone got more than one collection in a class like this to work? Or seen a bug like this?

Im sorry if there is anything obvious that I'm missing, I've searched everywhere for a few days now and have come up with nothing! Maybe Im using incorrect words etc...

Im using the JetDriver with an Access database as the back end.

Any help would be very much appreciated. I am going to attempt to work around this flaw now in order to make some progress, but would like to resolve the issue.

Many thanks in advance
Anthony Lawlor

Stack trace if interested:
Code:
   at NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate(IPersistentCollection collection, Object id, ISessionImplementor session)
   at NHibernate.Impl.ScheduledCollectionRecreate.Execute()
   at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
   at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
   at NHibernate.Impl.SessionImpl.Execute()
   at NHibernate.Impl.SessionImpl.Flush()
   at DataObjects.DataAccess.DataModule.Save(ITableObject obj) in C:\dev\DataObjectsCommon\src\DataAccess\DataModule.cs:line 39
   at DataObjectsTest.TestWindowEditPolicyWriteAndRead.TestWriteWindowEditPolicy() in C:\dev\tb\src\DataModuleTest\TestWindowEditPolicyWriteAndRead.cs:line 58
--ADOException
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
   at NHibernate.JetDriver.JetDbCommand.ExecuteNonQuery()
   at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation)
   at NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate(IPersistentCollection collection, Object id, ISessionImplementor session)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 10:04 pm 
Newbie

Joined: Wed Apr 11, 2007 12:24 am
Posts: 3
Location: Melbourne
Also, found this in the log...just before the exception

Seems I may be right, the collection seems to swap over....(hibernate gets confused)

Code:
2007-04-13 11:49:09,890 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] &lt;(null)&gt; - Collection found: [BizObjects.WindowTypes.WindowEditPolicy.AllowedFrames#1], was: [BizObjects.WindowTypes.WindowEditPolicy.AllowedGlasses#1]



You can see the pattern of the sql here.

Code:
NHibernate: INSERT INTO WindowEditPolicies (wepTimestamp, wepName, wepEditFrameMaterial, wepEditFramePfd, wepEditGlassType, wepEditHeight, wepEditWidth, wepEditTransomPosition, wepEditUseSameGlass, wepEditUseSameFrame, wepEditUseSameFrameMat, wepEditUseSameFramePfd, wepEditComments, wepEditAllowInSelector, wepEditAllowInSpecifier, wepEditRestrictGlass, wepEditRestrictFrame) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Edit Policy', @p2 = 'True', @p3 = 'True', @p4 = 'True', @p5 = 'True', @p6 = 'True', @p7 = 'True', @p8 = 'True', @p9 = 'False', @p10 = 'True', @p11 = 'True', @p12 = 'True', @p13 = 'True', @p14 = 'True', @p15 = 'True', @p16 = 'True'
NHibernate: select @@identity
NHibernate: UPDATE WindowEditPolicies SET wepTimestamp = ?, wepName = ?, wepEditFrameMaterial = ?, wepEditFramePfd = ?, wepEditGlassType = ?, wepEditHeight = ?, wepEditWidth = ?, wepEditTransomPosition = ?, wepEditUseSameGlass = ?, wepEditUseSameFrame = ?, wepEditUseSameFrameMat = ?, wepEditUseSameFramePfd = ?, wepEditComments = ?, wepEditAllowInSelector = ?, wepEditAllowInSpecifier = ?, wepEditRestrictGlass = ?, wepEditRestrictFrame = ? WHERE wepId = ?; @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Edit Policy', @p2 = 'True', @p3 = 'True', @p4 = 'True', @p5 = 'True', @p6 = 'True', @p7 = 'True', @p8 = 'False', @p9 = 'False', @p10 = 'True', @p11 = 'True', @p12 = 'True', @p13 = 'True', @p14 = 'True', @p15 = 'True', @p16 = 'True', @p17 = '1'
NHibernate: INSERT INTO GlassTypes (glsTimestamp, glsName, glsDescription, glsGuid, glsComments, glsLayers, glsThickness1, glsGap, glsThickness2, glsHoNac, glsHiNac, glsLambda1, glsLambda2, glsKEff, glsUValCenterWinter, glsUValCenterSummer, glsShgc, glsTSol, glsTVis, glsTUv, glsEmishOut, glsEmishIn, glsPurity1, glsPurity2, glsShadingCoefficient, glsTSolOutside, glsTSolInside, glsRSolOutside, glsRSolInside) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Glass Type Library Name', @p2 = 'Test Glass Type Library Description', @p3 = '', @p4 = 'Test Glass Type Comments', @p5 = '2', @p6 = '1.13', @p7 = '1.02', @p8 = '1.14', @p9 = '1.04', @p10 = '1.03', @p11 = '1.06', @p12 = '1.07', @p13 = '1.05', @p14 = '7.72', @p15 = '7.71', @p16 = '0.77', @p17 = '1.15', @p18 = '1.19', @p19 = '1.18', @p20 = '1.01', @p21 = '1', @p22 = '1.08', @p23 = '1.09', @p24 = '1.12', @p25 = '1.17', @p26 = '1.16', @p27 = '1.11', @p28 = '1.1'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingAngularData (angTimestamp, angName, angFieldDescription, angGlassDescription, angData0, angData10, angData20, angData30, angData40, angData50, angData60, angData70, angData80, angData90, angHemisphere) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Angular Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.05', @p10 = '1.06', @p11 = '1.07', @p12 = '1.08', @p13 = '1.09', @p14 = '1.1'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingAngularData (angTimestamp, angName, angFieldDescription, angGlassDescription, angData0, angData10, angData20, angData30, angData40, angData50, angData60, angData70, angData80, angData90, angHemisphere) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Angular Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.05', @p10 = '1.06', @p11 = '1.07', @p12 = '1.08', @p13 = '1.09', @p14 = '1.1'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingPolyData (polyTimestamp, polyName, polyFieldDescription, polyGlassDescription, polyATerm, polyBTerm, polyCTerm, polyDTerm, polyETerm, polyFit0, polyFit10, polyFit20, polyFit30, polyFit40, polyFit50, polyFit60, polyFit70, polyFit80, polyFit90, polyDat0, polyDat10, polyDat20, polyDat30, polyDat40, polyDat50, polyDat60, polyDat70, polyDat80, polyDat90, polyMaxError) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Poly Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.2', @p10 = '1.21', @p11 = '1.22', @p12 = '1.23', @p13 = '1.24', @p14 = '1.25', @p15 = '1.26', @p16 = '1.27', @p17 = '1.28', @p18 = '1.29', @p19 = '1.1', @p20 = '1.11', @p21 = '1.12', @p22 = '1.13', @p23 = '1.14', @p24 = '1.15', @p25 = '1.16', @p26 = '1.17', @p27 = '1.18', @p28 = '1.19', @p29 = '1.3'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingPolyData (polyTimestamp, polyName, polyFieldDescription, polyGlassDescription, polyATerm, polyBTerm, polyCTerm, polyDTerm, polyETerm, polyFit0, polyFit10, polyFit20, polyFit30, polyFit40, polyFit50, polyFit60, polyFit70, polyFit80, polyFit90, polyDat0, polyDat10, polyDat20, polyDat30, polyDat40, polyDat50, polyDat60, polyDat70, polyDat80, polyDat90, polyMaxError) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Poly Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.2', @p10 = '1.21', @p11 = '1.22', @p12 = '1.23', @p13 = '1.24', @p14 = '1.25', @p15 = '1.26', @p16 = '1.27', @p17 = '1.28', @p18 = '1.29', @p19 = '1.1', @p20 = '1.11', @p21 = '1.12', @p22 = '1.13', @p23 = '1.14', @p24 = '1.15', @p25 = '1.16', @p26 = '1.17', @p27 = '1.18', @p28 = '1.19', @p29 = '1.3'
NHibernate: select @@identity
NHibernate: INSERT INTO GlassTypes (glsTimestamp, glsName, glsDescription, glsGuid, glsComments, glsLayers, glsThickness1, glsGap, glsThickness2, glsHoNac, glsHiNac, glsLambda1, glsLambda2, glsKEff, glsUValCenterWinter, glsUValCenterSummer, glsShgc, glsTSol, glsTVis, glsTUv, glsEmishOut, glsEmishIn, glsPurity1, glsPurity2, glsShadingCoefficient, glsTSolOutside, glsTSolInside, glsRSolOutside, glsRSolInside) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Glass Type Library Name', @p2 = 'Test Glass Type Library Description', @p3 = '', @p4 = 'Test Glass Type Comments', @p5 = '2', @p6 = '1.13', @p7 = '1.02', @p8 = '1.14', @p9 = '1.04', @p10 = '1.03', @p11 = '1.06', @p12 = '1.07', @p13 = '1.05', @p14 = '7.72', @p15 = '7.71', @p16 = '0.77', @p17 = '1.15', @p18 = '1.19', @p19 = '1.18', @p20 = '1.01', @p21 = '1', @p22 = '1.08', @p23 = '1.09', @p24 = '1.12', @p25 = '1.17', @p26 = '1.16', @p27 = '1.11', @p28 = '1.1'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingAngularData (angTimestamp, angName, angFieldDescription, angGlassDescription, angData0, angData10, angData20, angData30, angData40, angData50, angData60, angData70, angData80, angData90, angHemisphere) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Angular Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.05', @p10 = '1.06', @p11 = '1.07', @p12 = '1.08', @p13 = '1.09', @p14 = '1.1'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingAngularData (angTimestamp, angName, angFieldDescription, angGlassDescription, angData0, angData10, angData20, angData30, angData40, angData50, angData60, angData70, angData80, angData90, angHemisphere) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Angular Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.05', @p10 = '1.06', @p11 = '1.07', @p12 = '1.08', @p13 = '1.09', @p14 = '1.1'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingPolyData (polyTimestamp, polyName, polyFieldDescription, polyGlassDescription, polyATerm, polyBTerm, polyCTerm, polyDTerm, polyETerm, polyFit0, polyFit10, polyFit20, polyFit30, polyFit40, polyFit50, polyFit60, polyFit70, polyFit80, polyFit90, polyDat0, polyDat10, polyDat20, polyDat30, polyDat40, polyDat50, polyDat60, polyDat70, polyDat80, polyDat90, polyMaxError) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Poly Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.2', @p10 = '1.21', @p11 = '1.22', @p12 = '1.23', @p13 = '1.24', @p14 = '1.25', @p15 = '1.26', @p16 = '1.27', @p17 = '1.28', @p18 = '1.29', @p19 = '1.1', @p20 = '1.11', @p21 = '1.12', @p22 = '1.13', @p23 = '1.14', @p24 = '1.15', @p25 = '1.16', @p26 = '1.17', @p27 = '1.18', @p28 = '1.19', @p29 = '1.3'
NHibernate: select @@identity
NHibernate: INSERT INTO GlazingPolyData (polyTimestamp, polyName, polyFieldDescription, polyGlassDescription, polyATerm, polyBTerm, polyCTerm, polyDTerm, polyETerm, polyFit0, polyFit10, polyFit20, polyFit30, polyFit40, polyFit50, polyFit60, polyFit70, polyFit80, polyFit90, polyDat0, polyDat10, polyDat20, polyDat30, polyDat40, polyDat50, polyDat60, polyDat70, polyDat80, polyDat90, polyMaxError) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); @p0 = '1/01/0001 12:00:00 AM', @p1 = 'Test Poly Data Set', @p2 = 'ASol', @p3 = 'Test Glass', @p4 = '1', @p5 = '1.01', @p6 = '1.02', @p7 = '1.03', @p8 = '1.04', @p9 = '1.2', @p10 = '1.21', @p11 = '1.22', @p12 = '1.23', @p13 = '1.24', @p14 = '1.25', @p15 = '1.26', @p16 = '1.27', @p17 = '1.28', @p18 = '1.29', @p19 = '1.1', @p20 = '1.11', @p21 = '1.12', @p22 = '1.13', @p23 = '1.14', @p24 = '1.15', @p25 = '1.16', @p26 = '1.17', @p27 = '1.18', @p28 = '1.19', @p29 = '1.3'
NHibernate: select @@identity
NHibernate: INSERT INTO wepAllowedFramesList (frmWindowEditPolicyId, FrameTypeId) VALUES (?, ?); @p0 = '1', @p1 = '1'


Dont know how to fix this...Anyone think I Should I log a bug?

Maybe this is an example of many-to-many being 'discouraged' hmmm.


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.