CodeSmith Community
Your Code. Your Way. Faster!

Join Table Issue

rated by 0 users
Answered (Verified) This post has 1 verified answer | 25 Replies | 2 Followers

Top 100 Contributor
54 Posts
Points 1,195
codrsmith posted on 01-21-2010 10:15 AM

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:

- foreign keys ids

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!

  • | Post Points: 35

Answered (Verified) Verified Answer

Top 50 Contributor
117 Posts
Points 3,540
Verified by blake05

Hello,

Yes, that sounds right. Smile
http://ayende.com/Blog/archive/2006/12/02/NHibernateCascadesTheDifferentBetweenAllAlldeleteorphansAndSaveupdate.aspx

Thanks,
Tom 

Tom DuPont
CodeSmith Tools, LLC. Software Development Engineer

  • | Post Points: 5

All Replies

Top 50 Contributor
117 Posts
Points 3,540

Hello,

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").

Thanks,
Tom 

Tom DuPont
CodeSmith Tools, LLC. Software Development Engineer

  • | Post Points: 35
Top 100 Contributor
54 Posts
Points 1,195

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"

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 5
Top 100 Contributor
54 Posts
Points 1,195

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.

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 5
Top 100 Contributor
54 Posts
Points 1,195

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" />

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 35
Top 50 Contributor
117 Posts
Points 3,540

Hello,

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?

Thanks,
Tom 

Tom DuPont
CodeSmith Tools, LLC. Software Development Engineer

  • | Post Points: 35
Top 100 Contributor
54 Posts
Points 1,195

Just found how to set an extended property to a specific column. In Microsoft SQL Server Management Studio ... I will try this.

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 5
Top 100 Contributor
54 Posts
Points 1,195

Had other things to focus on and my DB architecture to change. I will be back soon to resume this investigation.

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 35
Top 50 Contributor
117 Posts
Points 3,540

Hello,

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.

Thanks,
Tom 

Tom DuPont
CodeSmith Tools, LLC. Software Development Engineer

  • | Post Points: 35
Top 100 Contributor
54 Posts
Points 1,195

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.

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 5
Top 100 Contributor
54 Posts
Points 1,195

if I want to avoid cascade, should i use cs_cascade and set value to none?

Proud owner of CodeSmith Pro 5.2 License!

  • | Post Points: 35
Top 50 Contributor
117 Posts
Points 3,540
Verified by blake05

Hello,

Yes, that sounds right. Smile
http://ayende.com/Blog/archive/2006/12/02/NHibernateCascadesTheDifferentBetweenAllAlldeleteorphansAndSaveupdate.aspx

Thanks,
Tom 

Tom DuPont
CodeSmith Tools, LLC. Software Development Engineer

  • | Post Points: 5
Page 2 of 2 (26 items) < Previous 1 2 | RSS
Copyright © 2010 CodeSmith Tools, LLC