Skip to content

Commit f07181e

Browse files
committed
HHH-9468 : Add documentation about enabling NamingStrategyDelegator implementations
1 parent b6861d1 commit f07181e

File tree

3 files changed

+134
-17
lines changed

3 files changed

+134
-17
lines changed

documentation/src/main/docbook/devguide/en-US/Database_Access.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@
882882
<entry><para>--naming=<replaceable>eg.MyNamingStrategy</replaceable></para></entry>
883883
<entry>select a NamingStrategy</entry>
884884
</row>
885+
<row>
886+
<entry><para>--namingdelegator=<replaceable>eg.MyNamingStrategyDelegator</replaceable></para></entry>
887+
<entry>select a NamingStrategyDelegator</entry>
888+
</row>
885889
<row>
886890
<entry><para>--config=<replaceable>hibernate.cfg.xml</replaceable></para></entry>
887891
<entry>read Hibernate configuration from an XML file</entry>
@@ -901,6 +905,50 @@
901905
</tbody>
902906
</tgroup>
903907
</table>
908+
<note>
909+
<para>
910+
The options, <option>--naming</option> and <option>--namingdelegator</option>, should not be used together.
911+
</para>
912+
</note>
913+
<para>
914+
When annotations or JPA XML descriptors are used to map an entity, the
915+
<interfacename>org.hibernate.cfg.NamingStrategy</interfacename> API may not be
916+
flexible enough to properly generate default collection table or join column names that comply with the
917+
JPA specification. This is because the API does not provide all the necessary information
918+
(e.g., an entity's class name, along with its mapped name and primary table name) to compute the names
919+
properly. Due to this limitation, <interfacename>org.hibernate.cfg.NamingStrategy</interfacename> has
920+
been deprecated.
921+
</para>
922+
<para>
923+
<interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>,
924+
is a temporary replacement intended to provide more flexibility in a more-or-less compatible way.
925+
</para>
926+
<para>
927+
For backward compatibility, the default implementation,
928+
<classname>org.hibernate.cfg.naming.LegacyNamingStrategyDelegator</classname> delegates table and
929+
column name generation to an instance of the class specified by the <option>--naming</option>, if provided;
930+
otherwise, it delegates to an instance of <classname>org.hibernate.cfg.EJB3NamingStrategy</classname>.
931+
</para>
932+
<para>
933+
Hibernate provides <classname>org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator</classname> as
934+
an alternative that generates default table and column names that comply with the JPA specification when
935+
annotations or JPA XML descriptors are used to map an entity; table and column names generated for entities
936+
mapped using Hibernate-specific hbm.xml are unaffected.
937+
</para>
938+
<para>
939+
The option, <option>--namingdelegator</option>, can be set to
940+
<classname>org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator</classname> or the name of a
941+
custom implementation of <interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>.
942+
</para>
943+
<para>
944+
See source code or JavaDoc for <interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>
945+
and its implementations for details.
946+
</para>
947+
<para>
948+
A more comprehensive solution will be introduced in 5.0 that will replace both
949+
<interfacename>org.hibernate.cfg.NamingStrategy</interfacename> and
950+
<interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>.
951+
</para>
904952
<example>
905953
<title>Embedding SchemaExport into your application</title>
906954
<programlisting language="Java" role="JAVA"><xi:include href="extras/embedding_SchemaExport.java" xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" /></programlisting>

documentation/src/main/docbook/manual/en-US/content/configuration.xml

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,11 +1519,12 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
15191519
<literal>hibernate.show_sql</literal> enabled.</para>
15201520
</section>
15211521

1522-
<section xml:id="configuration-namingstrategy">
1523-
<title>Implementing a <literal>NamingStrategy</literal></title>
1522+
<section xml:id="configuration-namingstrategy" revision="1">
1523+
<title>Implementing a Naming Strategy</title>
15241524

1525-
<para>The interface <literal>org.hibernate.cfg.NamingStrategy</literal>
1526-
allows you to specify a "naming standard" for database objects and schema
1525+
<para>The interfaces, <interfacename>org.hibernate.cfg.NamingStrategy</interfacename>
1526+
and <interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>,
1527+
allow you to specify a "naming standard" for database objects and schema
15271528
elements.</para>
15281529

15291530
<para>You can provide rules for automatically generating database
@@ -1533,19 +1534,57 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
15331534
eliminating repetitive noise (<literal>TBL_</literal> prefixes, for
15341535
example). The default strategy used by Hibernate is quite minimal.</para>
15351536

1536-
<para>You can specify a different strategy by calling
1537-
<literal>Configuration.setNamingStrategy()</literal> before adding
1538-
mappings:</para>
1537+
<para>When annotations or JPA XML descriptors are used to map an entity, the
1538+
<interfacename>org.hibernate.cfg.NamingStrategy</interfacename> API may
1539+
not be flexible enough to properly generate default collection table or
1540+
join column names that comply with the JPA specification. This is because
1541+
the API does not provide all the necessary information (e.g., an entity's
1542+
class name, along with its mapped name and primary table name) to compute
1543+
the names properly. Due to this limitation,
1544+
<interfacename>org.hibernate.cfg.NamingStrategy</interfacename> has
1545+
been deprecated.</para>
1546+
1547+
<para><interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>,
1548+
is a temporary replacement intended to provide more flexibility in a more-or-less
1549+
compatible way.</para>
1550+
1551+
<para>For backward compatibility, the default implementation,
1552+
<classname>org.hibernate.cfg.naming.LegacyNamingStrategyDelegator</classname>
1553+
delegates table and column name generation to an instance
1554+
of <classname>org.hibernate.cfg.EJB3NamingStrategy</classname>.
1555+
You can specify a different <interfacename>org.hibernate.cfg.NamingStrategy</interfacename>
1556+
by calling <literal>Configuration.setNamingStrategy()</literal> before adding mappings:</para>
1557+
1558+
<programlisting role="JAVA">SessionFactory sf = new Configuration()
1559+
.setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
1560+
.addFile("Item.hbm.xml")
1561+
.addFile("Bid.hbm.xml")
1562+
.buildSessionFactory();</programlisting>
1563+
1564+
<para><literal>org.hibernate.cfg.ImprovedNamingStrategy</literal> is a
1565+
built-in strategy that might be a useful starting point for some
1566+
applications.</para>
1567+
1568+
<para>Hibernate provides <classname>org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator</classname>
1569+
as an alternative that generates default table and column names that comply with the
1570+
JPA specification when annotations or JPA XML descriptors are used to map an entity;
1571+
table and column names generated for entities mapped using Hibernate-specific hbm.xml
1572+
are unaffected. You can specify <interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>
1573+
by calling <literal>Configuration.setNamingStrategyDelegator()</literal> before adding mappings:</para>
15391574

15401575
<programlisting role="JAVA">SessionFactory sf = new Configuration()
1541-
.setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
1542-
.addFile("Item.hbm.xml")
1543-
.addFile("Bid.hbm.xml")
1544-
.buildSessionFactory();</programlisting>
1576+
.setNamingStrategyDelegator(ImprovedNamingStrategyDelegator.DEFAULT_INSTANCE)
1577+
.addFile("Item.hbm.xml")
1578+
.addFile("Bid.hbm.xml")
1579+
.buildSessionFactory();</programlisting>
1580+
1581+
<note><literal>Configuration.setNamingStrategy()</literal> and
1582+
<literal>setNamingStrategyDelegator()</literal> should not be used together.</note>
1583+
1584+
<para>A more comprehensive solution will be introduced in 5.0 that will replace both
1585+
<interfacename>org.hibernate.cfg.NamingStrategy</interfacename> and
1586+
<interfacename>org.hibernate.cfg.naming.NamingStrategyDelegator</interfacename>.</para>
15451587

1546-
<para><literal>org.hibernate.cfg.ImprovedNamingStrategy</literal> is a
1547-
built-in strategy that might be a useful starting point for some
1548-
applications.</para>
15491588
</section>
15501589

15511590
<section>

documentation/src/main/docbook/manual/en-US/content/toolset_guide.xml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279

280280
</section>
281281

282-
<section xml:id="toolsetguide-s1-3" revision="2">
282+
<section xml:id="toolsetguide-s1-3" revision="3">
283283
<title>Running the tool</title>
284284

285285
<para>
@@ -329,6 +329,10 @@
329329
<row>
330330
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
331331
<entry>select a <literal>NamingStrategy</literal></entry>
332+
</row>
333+
<row>
334+
<entry><literal>--namingdelegator=eg.MyNamingStrategyDelegator</literal></entry>
335+
<entry>select a <literal>NamingStrategyDelegator</literal></entry>
332336
</row>
333337
<row>
334338
<entry><literal>--config=hibernate.cfg.xml</literal></entry>
@@ -350,6 +354,12 @@
350354
</tgroup>
351355
</table>
352356

357+
<note>
358+
<para>
359+
The options, <option>--naming</option> and <option>--namingdelegator</option>, should not be used together.
360+
</para>
361+
</note>
362+
353363
<para>
354364
You can even embed <literal>SchemaExport</literal> in your application:
355365
</para>
@@ -447,7 +457,7 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
447457

448458
</section>
449459

450-
<section xml:id="toolsetguide-s1-6" revision="2">
460+
<section xml:id="toolsetguide-s1-6" revision="3">
451461
<title>Incremental schema updates</title>
452462

453463
<para>
@@ -485,6 +495,10 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
485495
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
486496
<entry>select a <literal>NamingStrategy</literal></entry>
487497
</row>
498+
<row>
499+
<entry><literal>--namingdelegator=eg.MyNamingStrategyDelegator</literal></entry>
500+
<entry>select a <literal>NamingStrategyDelegator</literal></entry>
501+
</row>
488502
<row>
489503
<entry><literal>--properties=hibernate.properties</literal></entry>
490504
<entry>read database properties from a file</entry>
@@ -497,6 +511,12 @@ new SchemaExport(cfg).create(false, true);]]></programlisting>
497511
</tgroup>
498512
</table>
499513

514+
<note>
515+
<para>
516+
The options, <option>--naming</option> and <option>--namingdelegator</option>, should not be used together.
517+
</para>
518+
</note>
519+
500520
<para>
501521
You can embed <literal>SchemaUpdate</literal> in your application:
502522
</para>
@@ -529,7 +549,7 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
529549

530550
</section>
531551

532-
<section xml:id="toolsetguide-s1-8" revision="1">
552+
<section xml:id="toolsetguide-s1-8" revision="2">
533553
<title>Schema validation</title>
534554

535555
<para>
@@ -560,6 +580,10 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
560580
<entry><literal>--naming=eg.MyNamingStrategy</literal></entry>
561581
<entry>select a <literal>NamingStrategy</literal></entry>
562582
</row>
583+
<row>
584+
<entry><literal>--namingdelegator=eg.MyNamingStrategyDelegator</literal></entry>
585+
<entry>select a <literal>NamingStrategyDelegator</literal></entry>
586+
</row>
563587
<row>
564588
<entry><literal>--properties=hibernate.properties</literal></entry>
565589
<entry>read database properties from a file</entry>
@@ -572,6 +596,12 @@ new SchemaUpdate(cfg).execute(false);]]></programlisting>
572596
</tgroup>
573597
</table>
574598

599+
<note>
600+
<para>
601+
The options, <option>--naming</option> and <option>--namingdelegator</option>, should not be used together.
602+
</para>
603+
</note>
604+
575605
<para>
576606
You can embed <literal>SchemaValidator</literal> in your application:
577607
</para>

0 commit comments

Comments
 (0)