6 Replies Latest reply on Jun 5, 2013 12:14 PM by surkov

    How to get db column comments with Hibernate reverse engineering?

    surkov

      Hi! I use DB Oracle and I have comments on every table column, how can I get them in my .java classes?

        • 1. Re: How to get db column comments with Hibernate reverse engineering?
          maxandersen

          you'll need to add $table.comment to the templates of hbm2java.

          • 2. Re: How to get db column comments with Hibernate reverse engineering?
            surkov

            Could you tell my where templates of hbm2java are situated? I have to edit them ? or I have to write them ? May be you have an example of $table.comment adding...

            • 3. Re: How to get db column comments with Hibernate reverse engineering?
              maxandersen

              They are inside the hibernatetools-*.jar.

               

              Unzip that jar.

               

              copy the hbm2java directory into your own directory, i.e. "templates" so you have templates/hbm2java/*.ftl

               

              Now use "templates" as your template path in hibernate code generation.

               

              It will now look in this directory before looking in the jar.

               

              Meaning you can add things into these *.ftl files and they should show up in your generated entities.

              • 4. Re: How to get db column comments with Hibernate reverse engineering?
                surkov

                Thanks it's worked!!! By it is another problem...It lost code page...I have Oracle UTF8 database and i use russian letters in comments. How can a resolve it ?

                 

                Here is generated comments (((....

                 

                /**

                           * ���������� �05.������� ������������

                           */

                          private RefAccreditationDomain refAccreditationDomain;

                 

                 

                my Hibernate.cfg.xml

                 

                <?xml version="1.0" encoding="UTF-8"?>

                <!DOCTYPE hibernate-configuration PUBLIC

                                    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

                                    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

                <hibernate-configuration>

                    <session-factory>

                        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

                        <property name="hibernate.connection.password">a</property>

                        <property name="hibernate.connection.url">jdbc:oracle:thin:@192.168.11.237:1521:devorcl</property>

                        <property name="hibernate.connection.username">ACRED</property>

                        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>       

                        <property name="hibernate.connection.useUnicode">true</property>       

                                    <property name="hibernate.connection.characterEncoding">UTF-8</property>

                                    <property name="hibernate.connection.charSet">UTF-8</property>

                    </session-factory>

                </hibernate-configuration>

                 

                 

                 

                and my PojoFields.ftl

                 

                <#foreach field in pojo.getAllPropertiesIterator()>

                          <#if pojo.getMetaAttribAsBool(field, "gen-property", true)>

                                    <#foreach column in field.columnIterator>

                                    <#if column.comment?exists && column.comment?trim?length!=0>

                                    /**

                                     * ${column.comment}

                                     */

                                    </#if>

                                    </#foreach>                                                                                                              

                                    ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}

                                    <#if pojo.hasFieldInitializor(field, jdk5)>

                                              = ${pojo.getFieldInitialization(field, jdk5)}

                                    </#if>;

                          </#if>

                </#foreach>

                • 5. Re: How to get db column comments with Hibernate reverse engineering?
                  maxandersen

                  can you try and ensure your java-vm runs with default character encoding set to UTF-8 ?

                   

                  Try adding -Dfile.encoding=UTF-8 on command line arguments for eclipse.

                   

                  I believe hibernate tools uses the default encoding which might explain this.

                  1 of 1 people found this helpful
                  • 6. Re: How to get db column comments with Hibernate reverse engineering?
                    surkov

                    Thanks it' worked))) a've added 

                    -Dfile.encoding=UTF-8 to my eclipce.ini file...))) .. And i have another one question. How can I change type Set to ArrayList<AnyType> in my in my generated files? Is there any simple way to do this?