-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Generate javadoc from comments on a database with hibernate
PostPosted: Mon Aug 16, 2010 10:25 am 
Newbie

Joined: Tue Jul 27, 2010 8:22 am
Posts: 4
Hello

I'm using Hibernate 3.3.2.GA and an Oracle database

I'm trying to generate javadoc comments from tables and/or columns comments in a Oracle database.
Some way to do this?

I have this SQL code defined in a table:
SQL
Code:
COMMENT ON TABLE "ITEM"  IS 'Table of items';

COMMENT ON COLUMN "ITEM"."CODE" IS 'Code';
COMMENT ON COLUMN "ITEM"."NAME" IS 'Description';
COMMENT ON COLUMN "ITEM"."BLOCKED" IS 'Blocked';


in my PojoFields.ftl template I have:
PojoFields.ftl
Code:
<#foreach property in entitygen.getAllPropertiesIterator()>
   <#if pojo.hasMetaAttribute(property, "field-description")>
   /**
    ${pojo.getFieldJavaDoc(property, 0)}
    */
   </#if>
      // código para gerar os campos...
   ...



The problem is: pojo.hasMetaAttribute() return false and getFieldJavaDoc() return empty.
I've tried with pojo.getFieldDescription() and the result are the same.


With OracleMetadataDialect I see that comments are visible and are stored in REMARKS
Code:
public Iterator getColumns(final String catalog, final String schema, final String table, String column)
...
element.put("COLUMN_NAME", rs.getString(1));
element.put("TABLE_SCHEM", rs.getString(2));
element.put("NULLABLE", new Integer(rs.getInt(3)));
element.put("COLUMN_SIZE", new Integer(rs.getInt(4)));
element.put("DATA_TYPE", new Integer(rs.getInt(5)));
element.put("TABLE_NAME", rs.getString(6));
element.put("TYPE_NAME", rs.getString(7));
element.put("DECIMAL_DIGITS", new Integer(rs.getInt(8)));
element.put("TABLE_CAT", null);
element.put("REMARKS", rs.getString(9));
...

Only here I can view the comments that have been properly loaded


Should I put the comments in another place (not in REMARKS)? I tried but i have the same result...

Can anyone help?


Top
 Profile  
 
 Post subject: Re: Generate javadoc from comments on a database with hibernate
PostPosted: Tue Aug 17, 2010 6:44 am 
Newbie

Joined: Tue Jul 27, 2010 8:22 am
Posts: 4
We have other alternative...

Code:
<#foreach property in entitygen.getAllPropertiesIterator()>

      /**
      <#foreach column in property.columnIterator>
      <#if column.comment?exists && column.comment?trim?length!=0>
       * ${column.comment}
      </#if>
      </#foreach>
        */
     // código para gerar os campos... 
     ...


Solved :)


Top
 Profile  
 
 Post subject: Re: Generate javadoc from comments on a database with hibernate
PostPosted: Sat Jun 02, 2012 10:10 pm 
Newbie

Joined: Sat Jun 02, 2012 9:32 pm
Posts: 1
Excellent! This is exactly what I was after. I had a similar problem when trying to extract database comments from DB2 when generating the POJOs. The comments would extract fine into the generated hbm.xml files, but not the POJOs. I'm using the Hibernate Tools Eclipse plugin.

The HBM exporter would properly generate <comment> tags within the <column> tag, but the JavaDocs would always be empty using the Domain Code java generator.

Modifying the pojo templates to use column.comment instead of pojo.getFieldJavaDoc worked great!
Thanx!


Top
 Profile  
 
 Post subject: Re: Generate javadoc from comments on a database with hibernate
PostPosted: Mon Jun 04, 2012 7:57 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Hey, that's nice. I was never annoyed enough to seriously research the problem, but it's sure nice to be able to fix this once I get around to doing that.
Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.