Hrm, I just tried that and no dice. :( I was assigning the IDs because originally I wanted string-based identifiers (I'm applying this to a legacy database) so I had to assign the Id (or key name) to the objects.
This is sooo frustrating, It seems like such a simple problem. I'll turn on full log4net later today and see what happens with it. Any other suggestions in the meantime? On Feb 10, 9:35 pm, Paul Batum <[email protected]> wrote: > Hi there, > > I'm not sure what the problem is, but everything you are doing seems > perfectly normal EXCEPT assigning the ID's. Have you tried it without > assigning IDs explicitly? > > Paul Batum > > On Wed, Feb 11, 2009 at 1:24 PM, x97mdr <[email protected]> wrote: > > > I am just starting to learn NHibernate now, I tried setting up a very > > simple example to play around and for some reason I cannot get > > cascading to work. I followed the example of the FirstExample project > > and tried to apply it to my domain. I have two classes with a one-to- > > many relationship between them. They are Variable and Relation > > (related to metadata we store in our environment). > > > The problem is that when I run the unit test which should save the > > relation and the related variable only the relation ever gets saved, > > if at all. > > > I have tried what seems to me to be every variation of the mappings to > > see if they would work but nothing has succeeded. The weird thing is, > > the FirstExample project (for both SQLite and when I point it to SQL > > Server Express) seem to work fine. There is something I am > > misunderstanding in my mappings. I even tried switching between using > > Save and SaveOrUpdate on the session variable. I'm using the trunk of > > the fluent-nhibernate project, including the nhibernate library in its > > tools directory (2.0.1) > > > Any help is greatly appreciated and sorry if its a bit of a newb > > question but its really bugging me! > > > Here are the classes for reference: > > > public class Variable : IEntity > > { > > public virtual long Id > > { > > get; > > set; > > } > > > public virtual Relation ParentRelation > > { > > get; > > set; > > } > > } > > > public class Relation : IEntity > > { > > public virtual long Id > > { > > get; > > set; > > } > > > public virtual IList<Variable> Variables > > { > > get; > > set; > > } > > > public Relation() > > { > > Variables = new List<Variable>(); > > } > > > public virtual void AddQuestion(Variable item) > > { > > item.ParentRelation = this; > > Variables.Add(item); > > } > > } > > > and here are the mappings: > > > public class VariableMap : ClassMap<Variable> > > { > > public VariableMap() > > { > > Id(x => x.Id); > > References(x => x.ParentRelation); > > } > > } > > > public class RelationMap : ClassMap<Relation> > > { > > public RelationMap() > > { > > Id(x => x.Id); > > HasMany(x => x.Variables) > > .Inverse() > > .Cascade.All(); > > } > > } > > > I have a little session provider to configure everything here: > > > public class MySessionProvider > > { > > private NHibernate.ISessionFactory _sessionFactory; > > private NHibernate.Cfg.Configuration _configuration; > > > public MySessionProvider() > > { > > _sessionFactory = Fluently.Configure() > > .Database( > > MsSqlConfiguration.MsSql2005 > > .ConnectionString(x => x.Is > > (@"Server=BUMBLEBEE > > \SQLEXPRESS;Database=EditImputation;Trusted_Connection=True;")) > > .ShowSql() > > ) > > .Mappings(x => > > x.FluentMappings.AddFromAssemblyOf<Relation>()) > > .ExposeConfiguration > > (StoreConfiguration) > > .BuildSessionFactory(); > > } > > > private void StoreConfiguration(NHibernate.Cfg.Configuration > > configuration) > > { > > _configuration = configuration; > > } > > > public NHibernate.ISession CreateSession() > > { > > return _sessionFactory.OpenSession(); > > } > > > public void BuildSchema() > > { > > new NHibernate.Tool.hbm2ddl.SchemaExport > > (_configuration).Create(false, true); > > } > > } > > > And I run everything in a unit test like this: > > > [TestMethod] > > public void Can_Add_Variable() > > { > > var relation = new Relation(); > > relation.Id = 9; > > > var variable = new Variable(); > > variable.Id = 99; > > > relation.AddQuestion(variable); > > > using (var session = sessionProvider.CreateSession()) > > { > > using (var transaction = session.BeginTransaction()) > > { > > session.Save(relation); > > } > > } > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" 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/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
