sequence like in oracle? well i never used oracle so I don't know how it works. can you elaborate more? On Tue, Sep 15, 2009 at 8:30 AM, Fabio Maulo <[email protected]> wrote:
> no. I mean sequence. > > 2009/9/15 Delucia <[email protected]> > > I'm not sure what exactly sequence-like mean. do you mean like identity >> columns in mssql? in any case what I mean is that the algorithm should be >> that the session factory reserves a range of keys by incrementing the >> next_hi and then this range will be available for all session to use on all >> entities and when the session factory consumes the range it reserves another >> one and so on. >> this is an easier algorithm than the current one that reserves a range per >> table and works better for winform applications. >> >> On Tue, Sep 15, 2009 at 12:10 AM, Fabio Maulo <[email protected]>wrote: >> >>> do you mean a sequence-like generator ? >>> >>> 2009/9/14 Delucia <[email protected]> >>> >>>> >>>> Fabio, you're absolutely right. I meant winform application in my >>>> example. I know that bigint has a lot of room but what about saving >>>> trips to the database. >>>> >>>> I have not looked at the HiLo implementation in NH but I think what is >>>> happening is that the SessionFactory is keeping the count of the last >>>> used id per table. so from the above example: >>>> >>>> using (var session = SessionSource.CreateSession()) >>>> { >>>> using (session.BeginTransaction()) >>>> { >>>> var customer = new Customer("Joe"); >>>> >>>> // this is asking the session factory for the next id >>>> // the sesion factory has nothing so it increments the next_hi >>>> in the database and returns 1001 >>>> session.SaveOrUpdate(customer); >>>> >>>> var customer2 = new Customer("Shmoe"); >>>> // this time the session factory has an availabe id value for >>>> the Customer entity type >>>> // and returns 1002 >>>> session.SaveOrUpdate(customer2); >>>> >>>> var employee = new Employee("Jack"); >>>> >>>> // for this entity type the session factory has no value and it >>>> has to increment the next_hi in the database >>>> // and return 2001 >>>> session.SaveOrUpdate(employee); >>>> } >>>> >>>> } >>>> >>>> >>>> I think this is not only inefficient but unnecessarily complicated and >>>> this complexity effects generating id values outside NH (you have to >>>> think about SSIS packages and what not). I think an easier and more >>>> effiect alternative if the SessionFactory does not keep track of id >>>> per table but per database. This way the third call to save the >>>> employee will return 1003 instead of 2002 and save a trip to the >>>> database and use less keys. In addition it is easier to implement >>>> outside NH because it doesn't have to know about the table it is >>>> accessing. >>>> >>>> >>>> On Sep 14, 6:09 pm, Fabio Maulo <[email protected]> wrote: >>>> > btw Delucia that is an improvement of HighLow defined in ORM >>>> theory.The >>>> > target of the improvement is : has a less fragmentation per table. >>>> > >>>> > In winform and 2 physical tiers you should use a little max-low (like >>>> 99) >>>> > >>>> > 2009/9/14 Delucia <[email protected]> >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > > Currently if I want to insert an object graph that has 2 entities >>>> that use >>>> > > HiLo for their Id, NH session will go to the database for two times, >>>> one >>>> > > time for each entity, and increment the next_hi count. I was >>>> assuming that >>>> > > the session will have to go once to the database and reserve a range >>>> to be >>>> > > used for all entities since all entities are using the same next_hi >>>> value >>>> > > that will guarantee they will not collide. here is an example: >>>> > > using (var session = SessionSource.CreateSession()) >>>> > > { >>>> > >>>> > > using (session.BeginTransaction()) >>>> > > { >>>> > > var customer = new Customer("Joe"); >>>> > >>>> > > session.SaveOrUpdate(customer); >>>> > >>>> > > var employee = new Employee { FirstName = >>>> "Sue", >>>> > > LastName = "Wong" }; >>>> > >>>> > > session.SaveOrUpdate(employee); >>>> > > } >>>> > >>>> > > session.Transaction.Commit(); >>>> > > } >>>> > > } >>>> > >>>> > > Given the max_Lo is set to 1000, this code will go to the database >>>> twice to >>>> > > increment the next_hi one time for the customer and one time for the >>>> > > employee. I think it should increment it only once per session. >>>> > >>>> > -- >>>> > Fabio Maulo- Hide quoted text - >>>> > >>>> > - Show quoted text - >>>> >>>> >>> >>> >>> -- >>> Fabio Maulo >>> >>> >>> >>> >> >> >> > > > -- > Fabio Maulo > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
