1 Reply Latest reply on Aug 4, 2010 6:57 AM by Christian Treptow

    table prefixes

    Christian Treptow Newbie



      i need some help with implementing the naming-strategy of hibernate.

      The problem is, that tables we want to read/write are prefixed with company-dependend names, for example



      These are tables from Mirosoft Dynamics Navision.


      According to this thread: https://forum.hibernate.org/viewtopic.php?t=983708 it is possible to prefix tables with a naming strategy.

      Another Inforamation can be found here: http://www.linuxtopia.org/online_books/jboss_documentation/jboss_app_platform_4.3_hibernate_reference_guide/jboss_hibernate_Configuration-Implementing_a_NamingStrategy.html

      1: this is possible in JBoss too?

      2: How do i implement this if i have to decide late after build, what the tableprefix is? I want to copy ears to our customer and deploy it to JBoss with a commandline including the prefix.

      3: what to do with the persistence.xml and the beans using the persistence unit? where and how should i load the config, my persitence unit gets injected!?



        • 1. Re: table prefixes
          Christian Treptow Newbie

          i think i found some solution, but im not that satisfied with it


          you can extend the persistence.xml with the following:


          <property name="hibernate.ejb.naming_strategy" value="com.mycompany.persistence.NamingStrategy"/>


          and create a Class NamingStrategy that extends org.hibernate.cfg.ImprovedNamingStrategy:


          import org.hibernate.cfg.ImprovedNamingStrategy;
          import org.hibernate.util.StringHelper;
          public class NamingStrategy extends ImprovedNamingStrategy {
              private static final long serialVersionUID = -734450386268904960L;
              public String classToTableName(String className) {
                  return StringHelper.unqualify(className);
              public String tableName(String tableName) {
                  return "%company%" + tableName;
              public String propertyToTableName(String className, String propertyName) {
                  return "%company%$" + classToTableName(className) + '_' + propertyToColumnName(propertyName);

          On deploy at customer you can compile this class and substititute %company% before.



          any other ideas?