I'm facing strange NH (NH3 trunk version) behavior. I have this class:

        public class MessageToDealers: Entity
        {
                public virtual string Title { get; set; }
                public virtual string Message { get; set; }
                public virtual IList<Dealer> Recipients { get; private set; }

                public MessageToDealers()
                {
                        Recipients = new List<Dealer>();
                }
        }

which is mapped using FluentNHibernate like this:

        public class MessageToDealersMap: EntityMap<MessageToDealers>
        {
                public MessageToDealersMap()
                {
                        Map(x => x.Title).Not.Nullable();
                        Map(x => x.Message).Not.Nullable().Default("");
                        HasManyToMany(x => x.Recipients);
                }
        }

My NH-map integration tests are running against SQLite and this test
passes without any problem:

                [Fact]
                public void CanMapRecipients()
                {
                        var dealers = new[]
                                {
                                        new Model.Entities.Dealer.Dealer 
{LastName = "a", Code = "a"},
                                        new Model.Entities.Dealer.Dealer 
{LastName = "b", Code = "b"},
                                };

                        dealers.ForEach(d => session.Save(d));

                        session.Flush();
                        session.Clear();

                        var message = new MessageToDealers{Title="title", 
Message = "msg"};
        
message.Recipients.AddRange(session.QueryOver<Model.Entities.Dealer.Dealer>().List());

                        session.Save(message);

                        session.Flush();
                        session.Clear();

                        var message2 = 
session.Load<MessageToDealers>(message.Id);
                        Assert.Equal(message.Title, message2.Title);
                        Assert.Equal(2, message2.Recipients.Count);
                }

My application is running against Oracle using the same NH mappings
and setup as the integration test, but when I run similar code like
the code in test above, the associated "Recipients" are not persisted
in DB. I turned on NH SQL logging and I can see that the unit test
executes single insert to MessageToDealer table and than two inserts
to persist the associated Recipients. When I log SQL from the
application I can see just single insert for MessageToDealer class/
table, but no more inserts for associated Recipients. The message save
operation is executed in a transaction in both cases. I was trying to
change the code in all possible ways, but can't make it working in the
Oracle application and just don't know what else to try. Any idea what
should I try to change to make it working?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to