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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---