@@ -1519,11 +1519,12 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
1519
1519
<literal >hibernate.show_sql</literal > enabled.</para >
1520
1520
</section >
1521
1521
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 >
1524
1524
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
1527
1528
elements.</para >
1528
1529
1529
1530
<para >You can provide rules for automatically generating database
@@ -1533,19 +1534,57 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
1533
1534
eliminating repetitive noise (<literal >TBL_</literal > prefixes, for
1534
1535
example). The default strategy used by Hibernate is quite minimal.</para >
1535
1536
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 >
1539
1574
1540
1575
<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 >
1545
1587
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 >
1549
1588
</section >
1550
1589
1551
1590
<section >
0 commit comments