Skip to content

Update the <any /> mapping documentation #1809

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

Merged
merged 1 commit into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions doc/reference/modules/basic_mapping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3353,24 +3353,25 @@
example, for audit logs, user session data, etc.
</para>

<programlisting><![CDATA[<any name="AnyEntity" id-type="Int64" meta-type="Eg.Custom.Class2TablenameType">
<column name="table_name"/>
<programlisting><![CDATA[<any name="AnyEntity" id-type="long" meta-type="class">
<column name="type"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

This does not have to be a table name.

<column name="id"/>
</any>]]></programlisting>

<para>
The <literal>meta-type</literal> attribute allows the application to specify a custom type that maps
database column values to persistent classes that have identifier properties of the type specified by
<literal>id-type</literal>. If the meta-type returns instances of <literal>System.Type</literal>,
nothing else is required. On the other hand, if it is a basic type like <literal>String</literal> or
<literal>Char</literal>, you must specify the mapping from values to classes.
<literal>id-type</literal>. If the meta-type is <literal>class</literal>, nothing else is required.
Copy link
Member Author

Choose a reason for hiding this comment

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

Support of TypeType is gone since NH 2.0, as reported in NH-1403. This has been fixed by "hijacking" the TypeType alias class for instead yielding ClassMetaType when class is used in the meta-type attribute of an any mapping (or ...-to-any).
(This can be confusing for those who know class is TypeType alias, because TypeType persists the assembly qualified type name whereas ClassMetaType persists the full-name instead (no assembly in it).)

The class full name will be persisted in the database as the type of the associated entity.
On the other hand, if it is a basic type like <literal>string</literal> or
<literal>char</literal>, you must specify the mapping from values to classes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not actually true: string and any string like types may work without meta-values. In such case they work somewhat similarly to class, but without a dedicated NHibernate MetaType. That causes issues, like those not fixed in #1803. So I have decide to keep that sentence.

If we fix this, this part would have to be updated.

</para>

<programlisting><![CDATA[<any name="being" id-type="long" meta-type="string">
<meta-value value="TBL_ANIMAL" class="Animal"/>
<meta-value value="TBL_HUMAN" class="Human"/>
<meta-value value="TBL_ALIEN" class="Alien"/>
<column name="table_name"/>
<meta-value value="ANIMAL_TYPE" class="Animal"/>
<meta-value value="HUMAN_TYPE" class="Human"/>
<meta-value value="ALIEN_TYPE" class="Alien"/>
<column name="type"/>
<column name="id"/>
</any>]]></programlisting>

Expand Down Expand Up @@ -3419,9 +3420,8 @@
</callout>
<callout arearefs="any3">
<para>
<literal>meta-type</literal> (optional - defaults to <literal>Type</literal>): a type that
maps <literal>System.Type</literal> to a single database column or, alternatively, a type
that is allowed for a discriminator mapping.
<literal>meta-type</literal> (optional - defaults to <literal>string</literal>): a type
that is allowed for a discriminator mapping, or <literal>class</literal>.
</para>
</callout>
<callout arearefs="any4">
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/modules/collection_mapping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ session.Update(category); // The relationship will be saved]]></programlist
<para>
The <literal>&lt;many-to-any&gt;</literal> and <literal>&lt;index-many-to-any&gt;</literal>
elements provide for true heterogeneous associations. These mapping elements work in the
same way as the <link linkend="mapping-types-anymapping"><literal>&lt;any&gt;</literal>
same way than the <link linkend="mapping-types-anymapping"><literal>&lt;any&gt;</literal>
element</link> - and should also be used rarely, if ever.
</para>

Expand Down