Thanks for the insight Diego, and sorry for posting on the wrong group. I was using an attribute-based session in view approach to transactions, but it appears that this is not working correctly (as you said - just looked like it it was with native id's). The problem seems to be that the transaction is no longer active when it comes to the tx.commit() - but anyway, I'll follow that up on the correct group. Cheers.
On May 30, 8:31 pm, Diego Mijelshon <[email protected]> wrote: > Actually, the question does not belong here, but in the users list (nhusers) > > However, the answer is simple enough to save you the roundtrip: you are not > flushing the session (and, probably, not using transactions either). > This seemed to work with native ids because inserts are done immediately to > get the new Id value. > > The correct workflow for saving new objects is: > using (var tx = session.BeginTransaction()) > { > session.Save(theNewObject); > tx.Commit(); > > } > > Diego > > On Sun, May 30, 2010 at 13:19, Sosh <[email protected]> wrote: > > Hi, > > > I originally posted this on the FluentNhibernate group, but they > > suggested I also post it here... > > > I've been building an app with Native Ids initially, and am now > > switching to HiLos. > > > However, I've come across a strange problem, and don't understand > > what's happening. > > > With native ids everything is working fine. However, if I one of the > > entity mappings to HiLo, new objects will not persist in the database > > (using SaveOrUpdate). I don't receive any errors and no exception is > > thrown - everything acts like it's working, but no new db records. > > > I'm just using default hilo settings. I'm recreating the DB with > > SchemaUpdate/Export beforehand, and the Hibernate_Unique_Key table > > with the next_hi column is being created correctly. > > > Here's the original mapping line that works: > > > Id(c => c.Id).GeneratedBy.Native(); > > > And the one that breaks everything: > > > Id(c => c.Id).GeneratedBy.HiLo("100"); > > > If I try to SaveOrUpdate() a new object, all I get in the sql logs is: > > > 2010-05-28 18:15:09,703 DEBUG 4 NHibernate.SQL - Reading high > > value:select next_hi from hibernate_unique_key for update > > 2010-05-28 18:15:09,718 DEBUG 4 NHibernate.SQL - Updating high > > value:update hibernate_unique_key set next_hi = ?p0 where next_hi = ? > > p1;?p0 = 4, ?p1 = 3 > > > And in the nhibernate log: > > > 2010-05-28 18:18:33,734 DEBUG 8 NHibernate.Impl.SessionImpl - > > [session- > > id=a948d92d-3edc-4f15-aa5a-3b7d461cb455] opened session at timestamp: > > 634106675137, for session factory: [/046fd6ce97f547aeb8a9edb8ddf6e2ef] > > 2010-05-28 18:18:33,734 DEBUG 8 NHibernate.Engine.IdentifierValue - > > unsaved-value: 0 > > 2010-05-28 18:18:33,734 DEBUG 8 > > NHibernate.Event.Default.AbstractSaveEventListener - transient > > instance of: xxxx.BusinessEvent > > 2010-05-28 18:18:33,734 DEBUG 8 > > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener - saving > > transient instance > > 2010-05-28 18:18:33,734 DEBUG 8 > > NHibernate.Event.Default.AbstractSaveEventListener - generated > > identifier: 304, using strategy: NHibernate.Id.TableHiLoGenerator > > 2010-05-28 18:18:33,734 DEBUG 8 > > NHibernate.Event.Default.AbstractSaveEventListener - saving > > [xxxx.BusinessEvent#304] > > 2010-05-28 18:18:33,734 DEBUG 8 NHibernate.Impl.SessionImpl - > > [session- > > id=a948d92d-3edc-4f15-aa5a-3b7d461cb455] running ISession.Dispose() > > 2010-05-28 18:18:33,734 DEBUG 8 NHibernate.Impl.SessionImpl - > > [session- > > id=a948d92d-3edc-4f15-aa5a-3b7d461cb455] executing real Dispose(True) > > 2010-05-28 18:18:33,734 DEBUG 8 NHibernate.Impl.SessionImpl - closing > > session > > 2010-05-28 18:18:33,734 DEBUG 8 NHibernate.AdoNet.AbstractBatcher - > > running BatcherImpl.Dispose(true) > > > Versions: > > NHibernate 2.1.2.4000 > > MySQL5Dialect > > MySQL5.0.67 > > > I'm a bit stumped - any ideas what the problem might be? Or what to > > check? > > > Thanks > >
