I'm not sure I understand the question. Are you asking whether or not you can save both the Company and Employee (where there is a parent-child relationship between the 2) in a single transaction? If so, then the answer is yes... provided you have your relationships wired correctly between Company-Employee in your NH mappings..
NHibernate is capable of saving as many objects (rows in a database) as using native ado.net..... On Wed, Jul 29, 2009 at 12:12 PM, Niclas Pehrsson <[email protected]>wrote: > > ow sorry I forgot it in my example :| > > <class name="Employee" /> > ..... > <many-to-one name="Company" class="Company" not-null="true" /> > </class> > > why can't I use the following transaction? > > var company = new Company(); > var employee = new Employee(); > employee.Company = company; > > using(var transaction = session.BeginTransaction()) > { > session.Save(company); > session.Save(employee); > transaction.Commit(); > } > > > corrected :) > On Jul 29, 8:08 pm, Greg Young <[email protected]> wrote: > > What is employee->company supposed to be pointing to? you never set it > > to anything and you have declared it not null. > > > > > > > > On Wed, Jul 29, 2009 at 2:04 PM, Niclas Pehrsson<[email protected]> > wrote: > > > > > Hi if I for example has the following mapping > > > > > <class name="Employee" /> > > > ..... > > > <many-to-one name="Company" class="Company" not-null="true" /> > > > </class> > > > > > why can't I use the following transaction? > > > > > var company = new Company(); > > > var employee = new Employee(); > > > > > using(var transaction = session.BeginTransaction()) > > > { > > > session.Save(company); > > > session.Save(employee); > > > transaction.Commit(); > > > } > > > this will give me exception on session.save(employee); because it > > > could not find company in db. Can I solve it somehow so I don't need > > > to have in 2 transactions and not need to let the employee has the > > > responsibility to save company? (using assigned id, if it has > > > something to do with it?). > > > > -- > > Les erreurs de grammaire et de syntaxe ont été incluses pour m'assurer > > de votre attention > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
