Please tell me what is the expected form of my database tables for a correct generation/work of NHibernate.
Actually I have entity datatables with:
- id
- foreign keys ids
- fields
and some join datatables:
The problem seems if i don't create an id column for the join datatables, else their name appear nowhere in the generated code...
Also if my entity datatable has no field, it is not generated. This can be avoided with adding an extended property "cs_ManyToMany" with a value being "False" or by adding a field (nullable bit typed for smaller memory usage).
My question is: how are my datatables supposed to be so that the generated code works correctly (meaning the join datatables are filled (inserts) automatically when i save a entity object refering to it?
Proud owner of CodeSmith Pro 5.2 License!
Hello,
Yes, that sounds right. http://ayende.com/Blog/archive/2006/12/02/NHibernateCascadesTheDifferentBetweenAllAlldeleteorphansAndSaveupdate.aspx
Thanks,Tom
Tom DuPontCodeSmith Tools, LLC. Software Development Engineer
Siiiiigh, it's not working because I left yet another bug in there! I am very sorry for sending you on wild goose chase with all these versions!Please try 1343, and set the extended property cs_cascade of the column to the value you want to use for the cascade ("all").
It doesn't work it seems....
I don't get any cascade in my hbm file. Should I do it on both link ends? (the 2 related tables)
Because I tried it too... no success with both values of all or "all"
If I put cs_cacade with a value all for S and ST datatables, I get :
S.hbm.xml
<many-to-one name="ST" column="[STid]" class="ST" />
ST.hbm.xml
<bag name="Ss" lazy="true" cascade="all-delete-orphan" inverse="true" >
<key column="[STid]"></key>
<one-to-many class="S"></one-to-many>
</bag>
I tried then to add cs_cascade all to R too but it doesn't change a thing. No cascade is being added to my many-to-one S in R.
If I put no cs_cascade at all I just add this in R.hbm.xml and it works:
before:
<many-to-one name="S" column="[Sid]" class="S" />
after:
<many-to-one name="S" column="[Sid]" class="S" cascade="all" />
The extended property needs to be placed on the Many-To-One column, so R.Fid needs to have it's "cs_cascade" extended property set.Can you confirm that this is not working if the column's extended property is set?
Just found how to set an extended property to a specific column. In Microsoft SQL Server Management Studio ... I will try this.
Had other things to focus on and my DB architecture to change. I will be back soon to resume this investigation.
That is fine, please let us know how it goes when you get the opportunity to test this further. Thank you for you're persistence, patience, and help with these issues!I have released NHibernate v1.1.6; these cascade changes are in there, as well as some more Unit Test fixes.
I simplified my database :
Then I don't need for my particular and current case the cs_manytomany extended property for R table anymore. By the way I still have issues with cascading... will try to list them in my next post.
if I want to avoid cascade, should i use cs_cascade and set value to none?