1 Reply Latest reply on Sep 7, 2007 4:09 AM by gindhart

    Column names in embedded classes

    gindhart

      Hi again !

      Some of my embeddable classes are embedded more then once in a class.
      So I am forced to override the column names to avoid to get a duplicate column names error for the attributes of the embedded class.

      Is there any option to enable (e.g.) appending the the embedded colname to the attribute name in the embedding class for creation of the complete column name ?
      Or is there a workaround which I do not know, yet ?

      Thanks for every hint !

      Werner

        • 1. Re: Column names in embedded classes
          gindhart

          Hi !

          I found out the answer by myself.
          Maybe someone else will find the answer useful:

          The default naming strategy does not regard the path thru the embedded classes to the actual entity column.

          Hibernate provides an alternativ naming strategy handler which can be activated in persistence.xml using the line:

          <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy"/>


          Unfortunately this out of the box naming strategy class produces some SQL grammar (mysql) errors in my case.

          So I had to implement my own strategy,
          activated using the line above replaced with the class name by my own strategy class.
          (Sorry, I can not publish the entire class here, because I haven't got the legal rights on it)

          For example the method propertyToColumnName could be implemented like this:

          public String propertyToColumnName(String name) {
           StringBuffer buf = new StringBuffer(name.length() );
           String[] parts = name.split("\\.");
           for (int i = 0; i < parts.length; i++) {
           if (i > 0) {
           buf.append("$");
           }
           buf.append(parts.toLowerCase());
           }
           return buf.toString();
           }