Skip to content

Conversation

mickfold
Copy link
Contributor

https://nhibernate.jira.com/browse/NH-1262

This is a direct port of the cascade delete orphan functionality for one-to-one mappings from Hibernate to NHibernate.

This commit supports the following cases:

  1. Bidirectional primary key based one-to-one.
  2. Unidirectional shared primary key based one-to-one
  3. Bidirectional foreign key based one-to-one with orphan delete declared on the non-constrained (<one-to-one/>) side.
  4. Bidirectional foreign key based one-to-one with orphan delete declared on the constrained (<many-to-one unique="true"/>) side.
  5. Unidirectional foreign key based one-to-one with orphan delete declared on the constrained (<many-to-one unique="true"/>) side.
  6. Unidirectional foreign key based one-to-one with orphan delete declared on the constrained side (<many-to-one unique="true"/>) where the foreign key is composite (multiple columns).

Further information can be found in the original work for Hibernate https://hibernate.atlassian.net/browse/HHH-4726

@hazzik
Copy link
Member

hazzik commented Dec 13, 2012

@mickfold could you please update documentation to reflect these changes?

@mickfold
Copy link
Contributor Author

@hazzik I don't know how to do update the documentation on nhforge. Is there a guide on how to do this?

@oskarb
Copy link
Member

oskarb commented Dec 19, 2012

@mcharalambous The reference documenation is in DocBook XML in the doc directory of the code repository. Publishing to nhforge will happen later.

@mickfold
Copy link
Contributor Author

@oskarb thanks.

@mickfold
Copy link
Contributor Author

@hazzik and @oskarb I've made a (minor) update to the docs to reflect the changes to the cascade options. Would you like for me to expand on this? I could add to the section on one-to-one putting some further information about the variations of one-to-one mapping that NHibernate supports.

@dschilling
Copy link
Contributor

I'm currently wishing this issue was fixed. However, it looks like this pull request does more than adding all-delete-orphan to one-to-one. It also introduces a new cascade, delete-orphan, to NHibernate. Is this from porting the Hibernate code?

@mickfold
Copy link
Contributor Author

@dschilling Yes, everything that was added was done so because it was part of the Hibernate feature HHH-4726. When porting the feature I tried to stick as closely to the original hibernate code as possible with the aim of getting the ported unit tests to pass.

@hazzik
Copy link
Member

hazzik commented May 7, 2014

@mickfold could you please rebase your PR on top of master branch? Thanks.

@hazzik
Copy link
Member

hazzik commented May 21, 2014

@mickfold ?

@mickfold
Copy link
Contributor Author

@hazzik Sorry for the delay. I have rebased my PR on to the top of the master branch. Please let me know if it looks okay. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please fix formatting here?

@mickfold
Copy link
Contributor Author

@hazzik I've fixed the formatting issue you highlighted. Please let me know if you find anything else which needs to be fixed. Thanks.

@hazzik
Copy link
Member

hazzik commented May 21, 2014

There is probably one big things need to be done: make this work with MappingByCode as well, if it is not supported yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With capital letter, please

@hazzik
Copy link
Member

hazzik commented May 21, 2014

Can you please make sure that code follows C# code conventions? Methods and properties with capital letter. Thanks

@mickfold
Copy link
Contributor Author

@hazzik Yes, those are the commits I ported but due to some implementation differences, such as classes like HbmBinder existing in Hibernate but not NHibernate, the port is not a line for line copy. I did try to make the test cases as close to the original Java code as close as possible though.

I've also updated all the tests code so methods and properties have capital letters and have started to work on MappingByCode.

@hazzik
Copy link
Member

hazzik commented Aug 18, 2014

@mickfold Any news on MappingByCode support?

@mickfold
Copy link
Contributor Author

@hazzik I'm down to one failing test case which is the Bidirectional Foreign Key Composite Id test. From looking at the XML code generated by the MappingByCode its missing out some properties which is causing problems, i.e.

mc.ManyToOne<EmployeeInfo>(x => x.Info, m =>
{
  m.Unique(true);
  m.NotFound(NotFoundMode.Exception);
  m.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
  m.Columns(x => { x.Name("COMP_ID"); }, x => { x.Name("PERS_ID"); });
});

when exported to XML becomes:

<many-to-one name="Info" cascade="all,delete-orphan">
  <column name="COMP_ID" />
  <column name="PERS_ID" />
</many-to-one>

but should be

<many-to-one name="Info" unique="true" cascade="all,delete-orphan"  not-found="exception">
  <column name="COMP_ID" />
  <column name="PERS_ID" />
</many-to-one>

I'm investigating why this is happening at the moment.

@mickfold
Copy link
Contributor Author

@hazzik one-to-one cascade delete orphan is now supported in MappingByCode.

Btw there are now 3 tests that are now failing which are checking for unsupported cascade styles. These are now redundant, should I delete them? I've listed the tests below.

AnyMapperTest.AutoCleanInvalidCascade
ManyToOneMapperTest.AutoCleanUnsupportedCascadeStyle
OneToOneMapperTest.AutoCleanUnsupportedCascadeStyle

Finally, one strange thing I discovered is that if you specify columns in the mapper it resets a lot of other fields to the default values, which mean I had to change the order of the mapping to the following to get it to work.

mc.ManyToOne(x => x.Info, m =>
{
m.Columns(x => { x.Name("COMP_ID"); }, x => { x.Name("PERS_ID"); });
m.Unique(true);
m.NotFound(NotFoundMode.Exception);
m.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
});

@hazzik
Copy link
Member

hazzik commented Aug 24, 2014

Yes, please delete these tests

@mickfold mickfold force-pushed the NH-1262 branch 3 times, most recently from 3f9ac00 to 736069f Compare August 28, 2014 12:14
@mickfold
Copy link
Contributor Author

@hazzik I've removed the redundant test. Should I squash the 5 commits into a single commit?

@hazzik
Copy link
Member

hazzik commented Aug 29, 2014

Great work, @mickfold! Thanks!

@hazzik
Copy link
Member

hazzik commented Aug 29, 2014

LGTM!

@hazzik hazzik added this to the 5.0.0 milestone Sep 21, 2014
@hazzik hazzik modified the milestones: 4.1.0, 5.0.0 Oct 18, 2014
@oskarb
Copy link
Member

oskarb commented Oct 22, 2014

In general I prefer to reserve the NHSpecificTest//NHxxxx convention for specific bug tests or corner cases. For basic functionality it would be better to organize the tests by functional area. Isn't there any existing test case folders for cascade etc., where these test cases or fixtures should be added?

@mickfold
Copy link
Contributor Author

mickfold commented Nov 5, 2014

@oskarb There's a cascade folder off the root test project. The tests could be moved there. What do you think?

@hazzik
Copy link
Member

hazzik commented Nov 18, 2014

Ok @mickfold can you please implement changes requested by @oskarb and rebase the PR on top of master branch?

@mickfold
Copy link
Contributor Author

@hazzik @oskarb just to clarify. Should I move the tests to the Cascade folder?

@hazzik
Copy link
Member

hazzik commented Nov 18, 2014

@mickfold sure

@mickfold mickfold force-pushed the NH-1262 branch 2 times, most recently from a365cf6 to 2c2881a Compare November 19, 2014 23:03
…ne mappings from Hibernate to NHibernate.

Mappings can be made in XML or MappingByCode.

The following scenarios are supported:

1) Bidirectional primary key based one-to-one.
2) Unidirectional shared primary key based one-to-one
3) Bidirectional foreign key based one-to-one with orphan delete declared on the non-constrained (<one-to-one/>) side.
4) Bidirectional foreign key based one-to-one with orphan delete declared on the constrained (<many-to-one unique="true"/>) side.
5) Unidirectional foreign key based one-to-one with orphan delete declared on the constrained (<many-to-one unique="true"/>) side.
6) Unidirectional foreign key based one-to-one with orphan delete declared on the constrained side (<many-to-one unique="true"/>) where the foreign key is composite (multiple columns).
@mickfold
Copy link
Contributor Author

@hazzik @oskarb The tests have been moved and the PR has been rebased on top of the master branch.

@hazzik
Copy link
Member

hazzik commented Nov 20, 2014

Thanks a lot @mickfold!

@hazzik hazzik merged commit 3e4cf2a into nhibernate:master Feb 22, 2015
@hazzik
Copy link
Member

hazzik commented Feb 22, 2015

Merged, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants