Nhibernate mapping does not save/insert keys of inserted subclasses?

I think it would be helpful if you could show us your classes as well. Have you checked that your Parent class really has a ParentID property of the type Parent, also I assume you have now removed the.

I think it would be helpful if you could show us your classes as well. Have you checked that your Parent class really has a ParentID property of the type Parent, also I assume you have now removed the from your mapping and replaced it with the many-to-one? Finally if you want your child objects to have collections of child objects then the child object will also need a many-to-one.

Im not sure if I understand you completely. Parent should have a property named ParentID of its own type? Like Parent ParentID {get; set;} At the moment ParentID is just an integer, im confused now :) – marn Mar 10 '10 at 11:13 Rather than adding a reference to the DocumentID you need to reference the actual parent object Document.

See the link for info on how to handle parent child situations - hope it helps nhforge. Org/doc/nh/en/index. Html#example-parentchild – Gareth Mar 10 '10 at 16:34 I've read trough the documentation close to 20x but I'm still missing something im affraid.

I posted a workaround below, and it has to do for the moment, but still open for suggestions. Currently i'm watching the summerofnhibernate. Com sessions.In the hope it get a little bit more clear for me.

– marn Mar 11 '10 at 9:58.

Gareth, I did indeed remove the double property. But im getting the error (posted in first posts update) when I keep the Im totally out of ideas of what is causing this My classes and their mappings look like this: (sorry for the amount of text incoming) Parent Object class (Document) namespace BusinessObjects. Correspondentie { public class Document : IDocument { public int DocumentID { get; set; } public IAcceptgiro Acceptgiro{ get; set; } public ICollection Bodyregels{ get; set; } } } Child Object class (DocumentBodyregel) namespace BusinessObjects.

Correspondentie { public class DocumentBodyregel : IDocumentBodyregel { public int ID { get; set; } public int DocumentID { get; set; } public ICollection Waardes { get; set; } } } And the last one (DocumentBodyregelWaarde) namespace BusinessObjects. Correspondentie { public class DocumentBodyregelWaarde : IDocumentBodyregelWaarde { public int ID { get; set; } public int DocumentID { get; set; } public int RegelID { get; set; } } } Document is mapped as follows: DocumentBodyregel is mapped like this: and the last one like this.

Sadly, after playing around with mappings and reading trough half the internet, I have not been able to solve this. The problem lies in the fact that I cant get to the scenario that gets his key from the database and after this Inserts this key into the foreignkey properties of its underlying classes, inside just one session.Save() call. E.g.

For scenario i'd like session. Save(document) -- * new document detected -- * get new identity -- * document has subclass with a foreignkey to it! -- * insert idenity into the specified foreignkey properties (guess here lies the problem) and repeat this with all underlying classes.

I did however come up with a workaround (most ugly code ever, but it gets the job done) Im not really into sharing code this crappy, but it just might help people reading here. I have not yet given up on solving this the right way, but for the moment this has to do. Stil open for a nudge in the better direction.

Incoming crap code! Public void InsertDocument(Document document) { using (ISession session = NOpenSession()) { using (ITransaction transaction = session. BeginTransaction()) { try { IDocument document2 = new Document(); document2.

Bodyregels = document. Bodyregels; //for making the query a little neater document. Bodyregels = null; //lets get the elusive identity session.

Save(document); session.Flush(); //reattach subclass and enter the id explicitly document. Bodyregels = document2. Bodyregels; foreach (DocumentBodyregel dbr in document.

Bodyregels) { dbr. DocumentID = document. DocumentID; } //save it again, now with filled FK session.

Save(document); session.Flush(); //now save the final subclass with FK's foreach (DocumentBodyregel dbr in document. Bodyregels) { foreach (DocumentBodyregelWaarde dbrw in dbr. Waardes) { dbrw.

RegelID = dbr. ID; dbrw. DocumentID = document.

DocumentID; } } //and save the entire thing again (now with FK's) session. Save(document); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions