What you have to do is more simple <id name="Id"> <generator class="guid"/> </id> and then remove any assignment of Id property (let NH do it for you).
On Thu, Jun 10, 2010 at 4:59 AM, Gytis <[email protected]> wrote: > Hi, > > we have ant old project with bad DB design, and now we are trying to > upgrade to 2.1.2. I've outlined my problem on stackoverflow, so maybe > i'll have more luck here :) > > > http://stackoverflow.com/questions/2858066/nhibernate-migration-from-1-0-2-0-to-2-1-2-and-many-to-one-save-problems > > If we take scenario that was provided on stackoverflow: > > //this Blog already exists in database > BlogEntity blog = new BlogEntity(); > blog.Id = Guid.Empty; > blog.Reference = 1; //Reference is unique, so we can > distinguish Blog by this field > blog.Name = "My blog"; > > //this is new Post, that we are trying to insert > PostEntity post = new PostEntity(); > post.Id = Guid.NewGuid(); > post.Name = "New post"; > post.Reference = 1234; > post.Blog = blog; > > session.Save(post); > > > digging deeper, I've found that nhibernate 2.1.2 executes query to > fetch BlogEntity: > > WARN: > Unable to determine if BlogEntity with assigned identifier > 00000000-0000-0000-0000-000000000000 is transient or detached; > querying the database. Use explicit Save() or Update() in session to > prevent this. > > Of course when querying, it gets null, and tries to insert PostEntity > with BlogId having null. But as i see nhibernate 1.0.2.0 does not try > to do the same. How can i force 2.1.2 act as 1.0.2.0 ? > > -- > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- 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.
