Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mixed formulas and columns #1808

Merged

Conversation

fredericDelaporte
Copy link
Member

@fredericDelaporte fredericDelaporte commented Jul 18, 2018

Many mapping elements allow to define their columns or formulas by nested elements, but most of them do not support having both nested columns and formulas.

Follow-up to NH-2117, which has added this support to one-to-many.

Why not qualifying this as a bug by the way, since nothing tells anywhere columns and formulas are not to be mixed.
A workaround could be in some cases to use formulas for columns too, but that can cause troubles to the DDL generation, as it cannot detect columns needing to be created when they are mapped as formulas.

This issue was spotted while checking this example.

This PR is #1759 rebased and squashed without the mapping-by-code part, since this part has some debate on its method naming, causing it to be blocked.

Possible breaking change:

  • Mappings mixing column elements and formula elements were taking into account only the formula elements. They will now take into account all elements.
  • Mappings mixing column elements and/or formula elements with a column attribute or a formula attribute were silently ignoring the attribute. They will now throw.
  • Mappings mixing a column attribute and a formula attribute were silently doing some best effort logic, either considering this as a two columns mapping, the second one being the formula (most cases), or only taking into account the formula (case of the <element> mapping). They will now throw.

@@ -6,18 +6,15 @@
<property name="Name" />
</class>

<!--
Mapping to demonstrate that the 'column' attribute takes precedence over a 'column' element - and, for consistency,
the same behaviour applies to the generator attribute/element
Copy link
Member Author

Choose a reason for hiding this comment

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

Wrong for column: that was the element which was taking precedence.
(NH-1007 is about adding the generator attribute as an alternate to specifying the element, when the user just needs to specify the generator name.)


<property name="Name" column="Name">
<column name="InvalidColumnName" />
</property>
Copy link
Member Author

Choose a reason for hiding this comment

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

It was demonstrating nothing, since InvalidColumnName is a valid column name. And it was actually the name used in database.

@hazzik hazzik changed the title Support mixed formulas and columns WIP Support mixed formulas and columns Jul 25, 2018
@hazzik hazzik changed the title WIP Support mixed formulas and columns Support mixed formulas and columns Jul 25, 2018
@hazzik
Copy link
Member

hazzik commented Aug 5, 2018

What's the precedence of elements and tags in other cases (eg. generators, etc.)?

@fredericDelaporte
Copy link
Member Author

fredericDelaporte commented Aug 5, 2018

As implied by this comment, in the case of generator, the attribute takes precedence over the element. (It looks to me as if the implementor of NH-1007 was mistakenly believing this was the priority used for columns, although it seems column elements have always taken precedence over attributes.)

For subselect, which support has been added quite later (NH-2602), the attribute also takes precedence over the element.

As already written, for column (and for formula), the element takes precedence over the attribute, and this seems to be the case since the first versions of NHibernate.

@hazzik
Copy link
Member

hazzik commented Aug 5, 2018

Ok, can we investigate Hibernate then?

@fredericDelaporte
Copy link
Member Author

Hibernate does not support the generator attribute, it only supports the element.

For subselect, the attribute also takes precedence over the element.

For column and formula, that is even yet another rule: the formula attribute takes precedence over all, then column and formula elements are considered (so, these elements are taken into account if there is no formula attribute), and last the column attribute is used (so, it is used if there is neither a formula attribute nor column of formula elements).

But maybe there is some validity checks done before parsing that I have not spotted.

hazzik
hazzik previously approved these changes Aug 14, 2018
Many mapping elements allow to define their columns or formulas by
nested elements, but most of them do not support having both nested
columns and formulas.

Follow-up to NH-2117, which has added this support to  one-to-many.
Throw on invalid usages of columns and formulas attributes and elements
Use a more robust checking of sub-elements existence
@hazzik
Copy link
Member

hazzik commented Aug 14, 2018

There is some cleanup required regards using of interpolated strings ($)

Remove superfluous string interpolation
@fredericDelaporte
Copy link
Member Author

I have made the cleanup. Do you consider your first approval as still holding true?

@hazzik
Copy link
Member

hazzik commented Aug 23, 2018

I’ll double check, but in principle - yes. I wanted to check something regarding the interfaces implemented (I think some of the classes are missing some interfaces, but I don’t remember the details)

@fredericDelaporte
Copy link
Member Author

Maybe you are thinking about one case which allows a nested formula or column element, but which indeed does not allow multiple ones, reason why I have not changed it. (I do not remember which case it was either, I just remember having seen it when I have checked all possible cases requiring this change.)

@fredericDelaporte
Copy link
Member Author

I have rechecked this, and spotted no forgotten case.

So,

As proposed on the development group, and since no continued grounded disagreement has been expressed there since one week after raised concerns being addressed, I intend to merge this PR next week (likely on Wednesday).

(I am issuing this notice on PR issued before starting to apply this handling of merges. I will not do it for new PR.)

@fredericDelaporte fredericDelaporte merged commit af5e6fa into nhibernate:master Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants