views:

18

answers:

1

I have set up Hibernate Tools from within Eclipse to autogenerate classes based on an existing DB. For each of the tables I have documented them and each of their columns within SQL Server. Is there a way to use that documentation information to comment the generated classes and to populate the schema entity documentation? I see that there are meta tags that can be put in the hbm.xml mapping files, but since I have those autogenerated each time I'd need to either add them back in or continually merge in new changes, plus I'd ideally like to have the DB be the "truth" information and not store this sort of information in the mapping files. Does anyone know if this is possible and if so how to do it? Thanks...

A: 

Is there a way to use that documentation information to comment the generated classes and to populate the schema entity documentation?

To my knowledge, tables and columns comments are used in some of the the generated files, at least in the following templates from hibernate-tools.jar:

  • doc/tables/table.ftl
  • hbm/column.hbm.ftl
  • hbm/persistentclass.hbm.ftl

For example, in hbm/column.hbm.ftl:

<#if column.isFormula()>
<formula>${column.getFormula()}</formula>
<#else>
<column name="${column.quotedName}" ${c2h.columnAttributes(column)}<#if column.comment?exists && column.comment?trim?length!=0>>
<comment>${column.comment}</comment>
</column><#else>/>
</#if>
</#if>

But they aren't used in the templates for annotated POJOs, you'd have to modify the templates for this.

Pascal Thivent
Does anyone know any good references for these template files? I am more than happy to try and create\modify templates, but I've never worked with them before so I'm not clear what I'd even need to do.
Grant Jones
@Grant These templates are actually Freemarker templates. Have a look at this [blog post](http://relation.to/2110.lace) for a very high level introduction. Then look at the Hibernate Tools [forum](https://forums.hibernate.org/viewforum.php?f=6) for existing questions (or post a new one). Sorry, can't be more specific.
Pascal Thivent