That's how it's supposed to work because NH 2.0 changed the default flush mode to Commit (see http://markmail.org/message/pjqelacrqu5jormi#query:+page:1+mid:gte3kefsewskmgfa+state:results).
Previously it was set to Auto, so NHibernate would flush the session before executing a query, making sure you didn't receive stale results. Now the presumption is that you *are* using a transaction and that you want to handle commit/rollback operations so it's up to you to commit it. Or change the FlushMode back to auto ;) HTH, Stuart On Tue, Aug 25, 2009 at 3:13 PM, Niklas Wendel<niklas.wen...@gmail.com> wrote: > > I actually got it working yesterday, but I haven't had time to write > it here. I didn't create a transaction around my SaveOrUpdate call in > the small test application originally, not sure why. As soon as I > added a transaction everything worked fine. > > Is that how it is supposed to work? I guess this is more of a > NHibernate question than a fluent-nhibernate question. Either way it > works fine for me now since in my real application I always had a > transaction. > > /NIklas > > On Aug 24, 3:12 pm, Paul Batum <paul.ba...@gmail.com> wrote: >> Niklas, I can't see anything wrong with the xml so I suspect your problem >> must be to do with how you are adding/saving the entities. Can you show me >> the relevant code? >> >> On Fri, Aug 21, 2009 at 11:41 PM, Niklas Wendel >> <niklas.wen...@gmail.com>wrote: >> >> >> >> >> >> > I have now upgraded and tried with the 1.0 RC and I am still seeing >> > the same behavior which is that the CondExpr_id column is always null >> > in the database. I have tried both with and without .Inverse(). I >> > have also changed the model slightly and removed the NotCond class and >> > replaced it with a boolean "Not" property in the Expr base class. >> >> > My exported mappings look like this: >> >> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- >> > access="property" auto-import="true" default-cascade="none" default- >> > lazy="true"> >> > <class xmlns="urn:nhibernate-mapping-2.2" >> > name="ExpressionMapping1.Model.Root, ExpressionMapping1, >> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> >> > <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, >> > Culture=neutral, PublicKeyToken=b77a5c561934e089"> >> > <column name="Id" /> >> > <generator class="identity" /> >> > </id> >> > <many-to-one cascade="all" name="Expr"> >> > <column name="Expr_id" /> >> > </many-to-one> >> > </class> >> > </hibernate-mapping> >> >> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- >> > access="property" auto-import="true" default-cascade="none" default- >> > lazy="true"> >> > <class xmlns="urn:nhibernate-mapping-2.2" lazy="false" >> > name="ExpressionMapping1.Model.Expr, ExpressionMapping1, >> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Expr`"> >> > <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, >> > Culture=neutral, PublicKeyToken=b77a5c561934e089"> >> > <column name="Id" /> >> > <generator class="identity" /> >> > </id> >> > <discriminator column="Type" type="String" insert="true" not- >> > null="true" /> >> > <property name="ExprType" >> > type="FluentNHibernate.Mapping.GenericEnumMapper`1 >> > [[ExpressionMapping1.Model.ExprType, ExpressionMapping1, >> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], >> > FluentNHibernate, Version=1.0.0.0, Culture=neutral, >> > PublicKeyToken=8aa435e3cb308880"> >> > <column name="ExprType" /> >> > </property> >> > <subclass name="ExpressionMapping1.Model.CondExpr, >> > ExpressionMapping1, Version=1.0.0.0, Culture=neutral, >> > PublicKeyToken=null"> >> > <property name="CondType" >> > type="FluentNHibernate.Mapping.GenericEnumMapper`1 >> > [[ExpressionMapping1.Model.CondType, ExpressionMapping1, >> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], >> > FluentNHibernate, Version=1.0.0.0, Culture=neutral, >> > PublicKeyToken=8aa435e3cb308880"> >> > <column name="CondType" /> >> > </property> >> > <bag cascade="all" inverse="true" name="Exprs"> >> > <key> >> > <column name="CondExpr_id" /> >> > </key> >> > <one-to-many class="ExpressionMapping1.Model.Expr, >> > ExpressionMapping1, Version=1.0.0.0, Culture=neutral, >> > PublicKeyToken=null" /> >> > </bag> >> > </subclass> >> > <subclass name="ExpressionMapping1.Model.PartExpr, >> > ExpressionMapping1, Version=1.0.0.0, Culture=neutral, >> > PublicKeyToken=null"> >> > <property name="SomeProperty" type="System.String, mscorlib, >> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> >> > <column name="SomeProperty" /> >> > </property> >> > </subclass> >> > </class> >> > </hibernate-mapping> >> >> > /Niklas >> >> > On Aug 17, 1:47 pm, Paul Batum <paul.ba...@gmail.com> wrote: >> > > I've ran out of ideas based on the code I've seen so far. I am thinking >> > it >> > > might be best if you migrate to using the recently released 1.0 RC >> > version >> > > of FNH as I can give you better assistance when working off that >> > codebase. >> > > If the problem still persists after migrating to 1.0 RC, can you please >> > > export your mappings and post them here, see: >> >http://wiki.fluentnhibernate.org/Fluent_configuration#Exporting_mappings >> >> > > On Mon, Aug 17, 2009 at 12:38 AM, Niklas Wendel <niklas.wen...@gmail.com >> > >wrote: >> >> > > > Unfortunatley adding an Inverse() made no difference. >> >> > > > /Niklas >> >> > > > On Aug 16, 2:11 pm, Paul Batum <paul.ba...@gmail.com> wrote: >> > > > > Try this: >> > > > > m.HasMany<Expr>(a => a.Exprs) >> > > > > .Cascade.All() >> > > > > .Inverse(); >> >> > > > > Also, for your NotExp you want the References() method not HasOne >> > (HasOne >> > > > is >> > > > > for One-to-One mappings which are quite rare). >> >> > > > > On Sun, Aug 16, 2009 at 9:22 PM, Niklas Wendel < >> > niklas.wen...@gmail.com >> > > > >wrote: >> >> > > > > > Thank you for the help. I turned off lazy-loading by implementing >> > a >> > > > > > ClassMap<Expr> where I set up the mappings for the Expr hierarchy >> > of >> > > > > > classes like this: >> >> > > > > > public ExprMap() >> > > > > > { >> > > > > > Not.LazyLoad(); >> >> > > > > > Id(x => x.Id); >> > > > > > Map(x => x.ExprType); >> >> > > > > > DiscriminateSubClassesOnColumn("Type") >> > > > > > .SubClass<CondExpr>(m => >> > > > > > { >> > > > > > m.Map(z => z.CondType); >> > > > > > m.HasMany<Expr>(a => a.Exprs).Cascade.All(); >> > > > > > }) >> > > > > > .SubClass<NotExpr>(b => >> > > > > > { >> > > > > > b.HasOne<Expr>(c => c.Expr).Cascade.All(); >> > > > > > }) >> > > > > > .SubClass<PartExpr>(d => >> > > > > > { >> > > > > > d.Map(e => e.SomeProperty); >> > > > > > }); >> > > > > > } >> >> > > > > > Now the first part works which is that I get the root object >> > pointing >> > > > > > to the correct subclass of Expr. >> >> > > > > > I did however encounter a new problem. When I add instances to the >> > > > > > Exprs list on the CondExpr instance I don't get them returned the >> > list >> > > > > > is always empty. When looking at the tables created the >> > CondExpr_id >> > > > > > column for the child Expr instances is always null so I don't see >> > any >> > > > > > relation between the different Expr instances. >> >> > > > > > I used sql to update the CondExpr_id for the child columns and set >> > the >> > > > > > correct parent id after that retrieving the data worked. >> >> > > > > > Am I missing something in my mapping which causes this? >> >> > > > > > /Niklas >> >> > > > > > On Aug 16, 9:16 am, Paul Batum <paul.ba...@gmail.com> wrote: >> > > > > > > Yes even this is the expected behavior. Try adding a virtual >> > method >> > > > to >> > > > > > Expr >> > > > > > > and override it in CondExpr and call it. You should find that the >> > > > > > CondExpr >> > > > > > > override gets called. >> >> > > > > > > If you really need to cast, there are a few tricks you can use, >> > some >> > > > of >> > > > > > them >> > > > > > > are listed here: >> >> >http://stackoverflow.com/questions/413237/getting-proxies-of-the-corr. >> > > > .. >> >> > > > > > > But really I suggest you turn off class level lazy loading for >> > your >> > > > Expr >> > > > > > > classes; all of those tricks are kinda nasty. >> >> > > > > > > Paul Batum >> >> > > > > > > On Sun, Aug 16, 2009 at 5:02 PM, Niklas Wendel < >> > > > niklas.wen...@gmail.com >> > > > > > >wrote: >> >> > > > > > > > Hej! >> >> > > > > > > > You understood it correct. Unfortunatley the behavior that you >> > > > > > > > describe where the ExprProxy gets turned into a CondExpr isn't >> > > > > > > > happening. Do I have to do something special to make it >> > happen? >> > > > > > > > Right now I have a line like this in my ExprType case >> > statement: >> >> > > > > > > > var condExpr = root.Expr as CondExpr; >> >> > > > > > > > and condExpr is always null after this. >> >> > > > > > > > /Niklas >> >> > > > > > > > On Aug 16, 8:00 am, Paul Batum <paul.ba...@gmail.com> wrote: >> > > > > > > > > Hi Niklas, >> >> > > > > > > > > Unless I am misunderstanding, the behavior you describe of a >> > Expr >> > > > > > proxy >> > > > > > > > > being loaded is correct. When NHibernate loads your Root >> > object, >> > > > the >> > > > > > > > > Root.Expr property gets loaded with a Expr proxy. When you >> > then >> > > > try >> > > > > > to >> > > > > > > > use >> > > > > > > > > the Expr object, NH goes to the DB, finds out the type of >> > object >> > > > > > (such as >> > > > > > > > > CondExpr) and loads that. So then if you call some >> > polymorphic >> > > > method >> > > > > > on >> > > > > > > > > your Root.Expr property, the CondExpr implementation will get >> > > > used. >> >> > > > > > > > > The point to realise is that the proxy has to be a Expr proxy >> > > > because >> > > > > > NH >> > > > > > > > > hasn't looked at the DB yet, so it cannot yet know the >> > derived >> > > > type. >> >> > > > > > > > > One option to avoid this behavior is to turn off lazy-loading >> > at >> > > > the >> > > > > > > > class >> > > > > > > > > level. I would still leave lazy-loading on for your >> > collections >> > > > > > though. >> >> > > > > > > > > Paul Batum >> >> > > > > > > > > On Sun, Aug 16, 2009 at 6:37 AM, Niklas Wendel < >> > > > > > niklas.wen...@gmail.com >> > > > > > > > >wrote: >> >> > > > > > > > > > Hej! >> >> > > > > > > > > > I am new to fluent-nhibernate and nhibernate and I am >> > having >> > > > some >> > > > > > > > > > problems with mapping the parts of my model where I use >> > > > > > inheritance. >> > > > > > > > > > I am using AutoPersistenceModel to do the mappings as much >> > as >> > > > > > possible >> > > > > > > > > > with IAutoMappingOverride<T> for the places where I need >> > it. >> >> > > > > > > > > > One part of the model which I am having problems with can >> > be >> > > > > > > > > > simplified to this: >> >> > > > > > > > > > public class Root >> > > > > > > > > > { >> > > > > > > > > > public virtual int Id { get; private set; } >> > > > > > > > > > public virtual Expr Expr { get; set; } >> > > > > > > > > > } >> >> > > > > > > > > > public abstract class Expr >> > > > > > > > > > { >> > > > > > > > > > protected Expr() >> >> ... >> >> read more »- Hide quoted text - >> >> - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---