in Education by
I have an identifying relationship between two tables in the database. The parent table has a primary key that is generated via an Identity. The child table has a primary key that is the identity-generated primary key from the parent table. It's a true one-to-one. I've tried several mapping strategies, with all sorts of results, none of them perfect. The parent mapping file has this (notice the Cascade.All() - I expect the parent to manage the relationship): HasOne(x => x.ChildObject).Cascade.All(); The child mapping has this: Id(Reveal.Member("ID")) .GeneratedBy.Foreign("ParentObject"); HasOne(Reveal.Member("ParentObject")) .Constrained() .ForeignKey(); I changed the object names to protect the innocent. So here's what happens. I create an instance of the parent, I create an instance of the child and set the relationships (add the Child to the Parent, and the Parent to the Child). I run this code: session.SaveOrUpdate(_Parent); session.Clear(); transaction.Commit(); What I expect to happen is the Parent gets saved, with the ID being updated in the parent from the database. Then the ID should be set in the Child, and the Child saved. Instead, the Parent gets saved, but not the Child (I can see the insert statements nHibernate is executing, and the Child object never appears in the database). The Child has the ID from the parent (it's being propagated from Parent to Child correctly), but nHibernate doesn't recognize the Child as dirty (a guess on my part). Even if I explicitly try a SaveOrUpdate on the Child object, it doesn't get saved. But it gets a bit weirder. If I attach a collection of dirty objects to the Child, and I call SaveOrUpdate explicitly on the Child, nHhiberante will persist the Child, and the collection - the expected behaviour. But I still have to call it explicitly. What mistake have I made mapping the Parent-Child relationship? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
My guess is that parent.Id is generated by identity. the line session.SaveOrUpdate(_Parent); will save the parent to get its id and cache the Insert of the Child to flush on commit. session.Clear(); will then remove the cached Insert and transaction.Commit(); wont find anything to do.

Related questions

0 votes
    _____ parameter of regression helps in identifying the direction of relationship between variables....
asked Nov 16, 2022 in Education by JackTerrance
0 votes
    I am trying to do some validation on the file name before it's saved. Here are my three file- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I am working on a voting table design using Postgres 9.5 (but maybe the question itself is applicable ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I am working on a voting table design using Postgres 9.5 (but maybe the question itself is applicable ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    The _______canvas helps you in identifying the key elements related to the problem. a) Problem scoping b) 4Ws ... cycle d) Algorithm Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    Which of the following can be defined as a family of activities for enhancing security by identifying objectives and ... of the options (3)Dynamic Analysis (4)Static Analysis...
asked May 19, 2021 in Technology by JackTerrance
0 votes
    _____________ aids in identifying the associations, correlations, and frequent patterns in data. Select the correct ... A)Clustering B)Classification C)Association Rule Mining...
asked Dec 3, 2020 in Technology by Editorial Staff
0 votes
    I create a plot_ly image using: MilesPlotly...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I create a plot_ly image using: MilesPlotly...
asked Jul 6, 2022 in Education by JackTerrance
0 votes
    I am working on wordpress with woocommerce and using WCK plugin for custom fields. I am creating products ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have a text file, by which I am trying to write to in my program. Whenever user wants to add ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I'm trying to implement the WMD editor used on StackOverflow to create some basic Wiki-style functionality. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
...