Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.0.2
Mapping documents:
relevant parts are:
parent:
Code:
<bag name="BookedRoomsUntyped" table="RoomBooking" lazy="false" cascade="all">
<key column="HotelBookingId"/>
<one-to-many class="Airtrade.Business.Hotels.RoomBooking, Airtrade.Business.Hotels"/>
</bag>
and child:
Code:
<many-to-one name="HotelBookingId" class="Airtrade.Business.Hotels.HotelBooking, Airtrade.Business.Hotels" column="HotelBookingId" />
also, it is important that in the Roombooking-mapping file there is a collection of persons.
Full stack trace of any exception that occurs:Name and version of the database you are using: Sql server 2005
The generated SQL (show_sql=true):See above at stacktrace: the thing is that the RoomBooking record is not saved to the database.
Debug level Hibernate log excerpt:Code:
2006-12-08 15:58:02,921 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl - Opened Reader, open Readers :1
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Persister.AbstractEntityPersister - Natively generated identity: 2581
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader - running NHybridDataReader.Dispose()
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl - Closed Reader, open Readers :0
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands :0
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades - processing cascades for: Airtrade.Business.Hotels.HotelBooking
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades - cascading to collection: Airtrade.Business.Hotels.HotelBooking.BookedRoomsUntyped
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades - unsaved-value: 0
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl - SaveOrUpdate() unsaved instance
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl - saving [Airtrade.Business.Hotels.RoomBooking#<null>]
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl - executing insertions
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades - processing cascades for: Airtrade.Business.Hotels.RoomBooking
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Airtrade.Business.Hotels.RoomBooking
2006-12-08 15:58:02,937 [TestRunnerThread] DEBUG NHibernate.Impl.WrapVisitor - Wrapped collection in role: Airtrade.Business.Hotels.RoomBooking.MappedGuests
2006-12-08 15:58:02,968 [TestRunnerThread] DEBUG NHibernate.Util.ADOExceptionReporter - Could not save object
System.ArgumentException: There is a problem with your mappings. You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>.
A ValueType can not be used with IdentityKey. The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=bds2rm%24ruc%241%40charly.heeg.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DSystem.Runtime.CompilerServices.RuntimeHelpers.GetHashCode%26sa%3DN%26tab%3Dwg
Parameter name: key
How come the Roombooking (child of HotelBooking) is not saved correctly to the database? What is wrong with my roombooking mapping?
I did get the parent-child relation to work when I also use the parent-object as a property in the child-object (instead of only the parent-KEYFIELD)
and then I had to use the following in the mappingfile of roombooking:
Code:
<many-to-one name="HotelBooking" column="HotelBookingId" class="Airtrade.Business.Hotels.HotelBooking, Airtrade.Business.Hotels" />
So, there is the parent-object defined, but I try to only define the parent-key in the mapping which does not work..
Why do I want to remove the parent-object? because than in code, I also have to assign the correct parent-object. And I think it is strange to have to assign the parent to the child, if NHibernate can see the parent-child relation in the mappingfile?
Is it possible to remove the many-to-one from the child-mapping file or is it really needed in the mappingfile?
Hope someone can help me out,