Does anyone know if there is any way to stop NHibernate performing selects when using POID = "assigned"?
On Feb 6, 9:57 pm, Billy Stack <[email protected]> wrote: > Found out the issue. > I was manually setting the Id of the OrderItem entity when the POID was > guid.comb. Changed the code to no longer set the Id and all worked as > expected. > > Still needed inverse="true" in child collection definition as otherwise > UPDATE statements (in the OrderItem table) were being generated. > > Thanks for the help. NHibernate can work with event sourcing! > > Billy Stack > > On Sun, Feb 6, 2011 at 3:26 PM, Richard Brown (gmail) < > > > > [email protected]> wrote: > > That should be fairly straightforward to do. I’d need to see your > > mappings and code to see what’s wrong in this case, but I suspect it’ll be > > that you want to use inverse=”true” on the collection (if you’re setting the > > back-pointer from the child to the parent yourself). > > > *From:* Billy Stack <[email protected]> > > *Sent:* Sunday, February 06, 2011 1:51 PM > > *To:* [email protected] > > *Subject:* Re: [nhusers] Re: [NH users] Re: When using id generator > > class="assigned", why does extra select take place > > Hi Richard, > > > Thanks for the information. > > I am now using guid.comb as the POID strategy. Our database is just simply > > storing events. > > This generates just an insert only when using a simple entity - which is > > what we want. > > > However I cant get it to work for complex types e.g an order with many > > order items. > > Is the following scenario possible? > > > Parent entity where POID = guid.comb > > Child entity where POID = guid.comb > > Note: One Parent has many children. > > > When I attempt to do a save I get an exception: > > > NHibernate: INSERT INTO MoreComplexMapping_Order (CustomerId, Description, > > Id) VALUES (@p0, @p1, @p2);@p0 = 1, @p1 = 'My new order', @p2 = > > dbe893b4-fa1c-4779-8f48-9e8200e36eb1 > > NHibernate: UPDATE MoreComplexMapping_OrderItem SET OrderId = @p0, > > Description = @p1 WHERE Id = @p2;@p0 = NULL, @p1 = 'desc 1', @p2 = > > 946475f6-f670-4a5b-945a-e033836ff002 > > 13:48:03,560 ERROR [ 7] AbstractFlushingEventListener [(null)]- Could not > > synchronize database state with session > > > It seems to attempt to do an update when I want it to do an insert. > > > Regards, > > Billy Stack > > > On Sun, Feb 6, 2011 at 10:17 AM, Richard Brown (gmail) < > > [email protected]> wrote: > > >> Hi Billy, > > >> The warning occurs when you call SaveOrUpdate() on an entity with an > >> 'assigned' identifier. > > >> When NH doesn't control the IDs, it can't tell if that instance should be > >> saved (it's new), or updated (it already exists in the DB), so it warns you > >> to let you know it's hitting the DB (twice) when you might not have > >> expected > >> it to. > > >> The fix that caused this behaviour: > >>http://216.121.112.228/browse/NH-1914 > >> The discussion on what it should do: > >>http://groups.google.com/group/nhibernate-development/browse_thread/t... > > >> Regards, > >> Richard > > >> *From:* Billy Stack <[email protected]> > >> *Sent:* Sunday, February 06, 2011 9:29 AM > >> *To:* [email protected] > >> *Subject:* Re: [nhusers] Re: When using id generator class="assigned", > >> why does extra select take place > >> The Id for the entity we were generating was a comb guid. Rather than > >> the code setting this we just changed the id generator to "guid.comb". No > >> select is performed by NHibernate by default when we perform a save. > > >> Thanks for the help > >> Billy Stack > > >> On Sat, Feb 5, 2011 at 3:10 PM, Jason Meckley > >> <[email protected]>wrote: > > >>> this worked in my situation, but the entities I was saving where > >>> children of a parent entity that was resolved from session. so the context > >>> is slightly different. In your situation it sounds like the entity with > >>> the > >>> assigned id is the root. > > >>> You know it's an insert only model, but NH doesn't know that, so it needs > >>> to check if it exists. There may be a mapping/configuration setting that > >>> prevents load before save, or prevents updates, but I not 100% sure about > >>> that. > > >>> If that doesn't work (or exist) I would change the POID strategy to allow > >>> NH/DB to handle it. If the assigned ID has business meaning, then map this > >>> as an immutable attribute of the entity. > > >>> Another option is to drop the use of NH altogether. I haven't used event > >>> sourcing myself, but what little I understand it suppose to simplify > >>> persistence concerns. If that's the case then NH or an RDBMS wouldn't be > >>> required. > > >>> -- > >>> 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 > >>> mailto:nhusers%[email protected]<nhusers%2Bunsubscribe@googlegroups.com>. > > >>> For more options, visit this group at > >>>http://groups.google.com/group/nhusers?hl=en. > > >> -- > >> 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 > >> mailto:nhusers%[email protected]<nhusers%2Bunsubscribe@googlegroups.com> > >> . > >> For more options, visit this group at > >>http://groups.google.com/group/nhusers?hl=en. > >> -- > >> 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 > >> mailto:nhusers%[email protected]<nhusers%2Bunsubscribe@googlegroups.com> > >> . > >> For more options, visit this group at > >>http://groups.google.com/group/nhusers?hl=en. > > > -- > > 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. > > > -- > > 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.- Hide quoted text - > > - Show quoted text - -- 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.
