Is this a bidirectional association? If yes, is the other end set to inverse=true?
Are you sure that you don't have a hidden try-catch-block somewhere that catches an exception and call transactionScope.VoteRollback()? This is a more common problem than most people can imagine. If none of the above is the problems core, please isolate the problem by removing all properties except the nullable many-to-one and the entities ID to reassure that not one of the other properties causes the rollback. Please don't misunderstand me as ruse, but I have never heard of spontaneous rollbacks of NHibernate before. -Markus 2009/5/1 Hexedit <[email protected]> > > First off I want to say thanks in advance for those who take the time > to read this and help out with this problem. > > I am writing an application using Castle ActiveRecord and Asp.NET MVC > and I've run into an issue I can't seem to diagnose. > > I have a class with the following property. > > Code: > > [BelongsTo("listing_agent", NotNull = false, NotFoundBehaviour = > NotFoundBehaviour.Ignore, > Cascade = CascadeEnum.None)] > public virtual Employee Agent > { > get { return _agent; } > set { _agent = value; } > } > > > The business logic behind this is that I have a bunch of sales > listings which may or may not have an Agent associated with it. > Whenever I try to create a sales listing with the Agent set to null, > the insert completes with no exception but is then immediately rolled > back by NHibernate. Here is the associated logs with this transaction: > > Quote: > > 16:22:24 [5] DEBUG NHibernate.Impl.SessionImpl - opened session at > timestamp: 633767053447 > 16:22:24 [5] DEBUG NHibernate.Transaction.AdoTransaction - Begin > (Unspecified) > 16:22:24 [5] DEBUG NHibernate.Connection.DriverConnectionProvider - > Obtaining IDbConnection from Driver > 16:22:24 [5] DEBUG > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener - saving > transient instance > 16:22:24 [5] DEBUG NHibernate.Event.Default.AbstractSaveEventListener > - saving [Westshore.Models.RentalProperty#<null>] > 16:22:24 [5] INFO NHibernate.Engine.Cascade - processing cascade > NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: > Westshore.Models.RentalProperty > 16:22:24 [5] INFO NHibernate.Engine.Cascade - done processing cascade > NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: > Westshore.Models.RentalProperty > 16:22:24 [5] DEBUG NHibernate.Event.Default.AbstractSaveEventListener > - executing insertions > 16:22:24 [5] DEBUG NHibernate.Event.Default.WrapVisitor - Wrapped > collection in role: Westshore.Models.RentalProperty.Pictures > 16:22:24 [5] DEBUG NHibernate.Event.Default.WrapVisitor - Wrapped > collection in role: Westshore.Models.RentalProperty.Availability > 16:22:24 [5] DEBUG NHibernate.Event.Default.AbstractSaveEventListener > - executing identity-insert immediately > 16:22:24 [5] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister > - Inserting entity: Westshore.Models.RentalProperty (native id) > 16:22:24 [5] DEBUG NHibernate.AdoNet.AbstractBatcher - Opened new > IDbCommand, open IDbCommands: 1 > 16:22:24 [5] DEBUG NHibernate.AdoNet.AbstractBatcher - Building an > IDbCommand object for the SqlString: INSERT INTO RentalProperties > (mls_number, allows_pets, air_conditioning_type, max_occupants, price, > square_feet, beds, baths, multi_family, garage_type, rental_floor, > furnished, bed_size, private_entrance, dining_room, floor_type, stove, > refridgerator, dishwasher, microwave, washer_dryer, description, > listing_agent, street, town, state, zip_code) VALUES > (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, > ?, ?); > select SCOPE_IDENTITY() > 16:22:24 [5] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister > - Dehydrating entity: [Westshore.Models.RentalProperty#<null>] > 16:22:24 [5] DEBUG NHibernate.Type.StringType - binding '' to > parameter: 0 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 1 > 16:22:24 [5] DEBUG NHibernate.Type.PersistentEnumType - binding '0' to > parameter: 2 > 16:22:24 [5] DEBUG NHibernate.Type.Int32Type - binding '0' to > parameter: 3 > 16:22:24 [5] DEBUG NHibernate.Type.DecimalType - binding '0' to > parameter: 4 > 16:22:24 [5] DEBUG NHibernate.Type.Int32Type - binding '0' to > parameter: 5 > 16:22:24 [5] DEBUG NHibernate.Type.DecimalType - binding '0' to > parameter: 6 > 16:22:24 [5] DEBUG NHibernate.Type.DecimalType - binding '0' to > parameter: 7 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 8 > 16:22:24 [5] DEBUG NHibernate.Type.PersistentEnumType - binding '0' to > parameter: 9 > 16:22:24 [5] DEBUG NHibernate.Type.PersistentEnumType - binding '0' to > parameter: 10 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 11 > 16:22:24 [5] DEBUG NHibernate.Type.PersistentEnumType - binding '0' to > parameter: 12 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 13 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 14 > 16:22:24 [5] DEBUG NHibernate.Type.PersistentEnumType - binding '0' to > parameter: 15 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 16 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 17 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 18 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 19 > 16:22:24 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to > parameter: 20 > 16:22:24 [5] DEBUG NHibernate.Type.StringClobType - binding '' to > parameter: 21 > 16:22:24 [5] DEBUG NHibernate.Type.Int32Type - binding null to > parameter: 22 > 16:22:24 [5] DEBUG NHibernate.Type.StringType - binding 'asdfasdf' to > parameter: 23 > 16:22:24 [5] DEBUG NHibernate.Type.StringType - binding 'asdf' to > parameter: 24 > 16:22:24 [5] DEBUG NHibernate.Type.StringType - binding 'ws' to > parameter: 25 > 16:22:24 [5] DEBUG NHibernate.Type.StringType - binding '45444' to > parameter: 26 > 16:22:24 [5] DEBUG NHibernate.Transaction.AdoTransaction - Enlist > Command > 16:22:24 [5] DEBUG NHibernate.AdoNet.AbstractBatcher - Opened > IDataReader, open IDataReaders: 1 > 16:22:24 [5] DEBUG NHibernate.Type.Int32Type - returning '27' as > column: > 16:22:24 [5] DEBUG NHibernate.Id.IdentifierGeneratorFactory - Natively > generated identity: 27 > 16:22:24 [5] DEBUG NHibernate.Driver.NHybridDataReader - running > NHybridDataReader.Dispose() > 16:22:24 [5] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed > IDataReader, open IDataReaders :0 > 16:22:24 [5] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed > IDbCommand, open IDbCommands: 0 > 16:22:24 [5] INFO NHibernate.Engine.Cascade - processing cascade > NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: > Westshore.Models.RentalProperty > 16:22:24 [5] INFO NHibernate.Engine.Cascade - done processing cascade > NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: > Westshore.Models.RentalProperty > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - flushing > session > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - processing > flush-time cascades > 16:22:24 [5] INFO NHibernate.Engine.Cascade - processing cascade > NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: > Westshore.Models.RentalProperty > 16:22:24 [5] INFO NHibernate.Engine.Cascade - done processing cascade > NHibernate.Engine.CascadingAction+SaveUpdateCascadingAction for: > Westshore.Models.RentalProperty > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - dirty > checking collections > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - Flushing > entities and processing referenced collections > 16:22:24 [5] DEBUG NHibernate.Engine.Collections - Collection found: > [Westshore.Models.RentalProperty.Pictures#27], was: [<unreferenced>] > (initialized) > 16:22:24 [5] DEBUG NHibernate.Engine.Collections - Collection found: > [Westshore.Models.RentalProperty.Availability#27], was: > [<unreferenced>] (initialized) > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - Processing > unreferenced collections > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - Scheduling > collection removes/(re)creates/updates > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - Flushed: 0 > insertions, 0 updates, 0 deletions to 1 objects > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - Flushed: 2 > (re)creations, 0 updates, 0 removals to 2 collections > 16:22:24 [5] DEBUG NHibernate.Impl.Printer - listing entities: > 16:22:24 [5] DEBUG NHibernate.Impl.Printer - > Westshore.Models.RentalProperty{'ID'='27', 'MLSNumber'='', > 'AllowsPets'='False', 'AirConditionioning'='0', 'MaxOccupants'='0', > 'Price'='0', 'SquareFeet'='0', 'Beds'='0', 'Baths'='0', > 'IsMultiFamily'='False', 'GarageType'='0', 'Rentalfloor'='0', > 'IsFurnished'='False', 'BedSize'='0', 'HasPrivateEntrance'='False', > 'HasDiningRoom'='False', 'FloorType'='0', 'HasStove'='False', > 'HasRefridgerator'='False', 'HasDishWasher'='False', > 'HasMicrowave'='False', 'HasWasherDryer'='False', 'Description'='', > 'Agent'='null', 'Pictures'='[]', 'Availability'='[]', > 'Address'='component[Street,Town,State,ZipCode]{'Street'='asdfasdf', > 'Town'='asdf', 'State'='ws', 'ZipCode'='45444'}'} > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - executing > flush > 16:22:24 [5] DEBUG NHibernate.AdoNet.ConnectionManager - registering > flush begin > 16:22:24 [5] DEBUG > NHibernate.Persister.Collection.ICollectionPersister - Inserting > collection: [Westshore.Models.RentalProperty.Pictures#27] > 16:22:24 [5] DEBUG > NHibernate.Persister.Collection.ICollectionPersister - collection was > empty > 16:22:24 [5] DEBUG > NHibernate.Persister.Collection.ICollectionPersister - Inserting > collection: [Westshore.Models.RentalProperty.Availability#27] > 16:22:24 [5] DEBUG > NHibernate.Persister.Collection.ICollectionPersister - collection was > empty > 16:22:24 [5] DEBUG NHibernate.AdoNet.ConnectionManager - registering > flush end > 16:22:24 [5] DEBUG > NHibernate.Event.Default.AbstractFlushingEventListener - post flush > 16:22:24 [5] DEBUG NHibernate.Transaction.AdoTransaction - Rollback > 16:22:24 [5] DEBUG NHibernate.Transaction.AdoTransaction - > IDbTransaction RolledBack > 16:22:24 [5] DEBUG NHibernate.Transaction.AdoTransaction - > IDbTransaction disposed. > 16:22:24 [5] DEBUG NHibernate.Impl.SessionImpl - transaction > completion > 16:22:24 [5] DEBUG NHibernate.AdoNet.ConnectionManager - aggressively > releasing database connection > 16:22:24 [5] DEBUG NHibernate.Connection.ConnectionProvider - Closing > connection > 16:22:24 [5] DEBUG NHibernate.Impl.SessionImpl - running > ISession.Dispose() > 16:22:24 [5] DEBUG NHibernate.Impl.SessionImpl - closing session > 16:22:24 [5] DEBUG NHibernate.AdoNet.AbstractBatcher - running > BatcherImpl.Dispose(true) > > > Is what I am trying to do impossible or am I missing something? When > the Agent property is set to a valid object that is persisted in the > database, the Listing gets created successfully. > > Any help would be greatly appreciated! > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
