After some investigation it seems like I should be able to build DTOs by modifying the existing Pojo templates (rather than creating a custom Exporter class).
One-to-many relationship properties can be detected and excluded using field.getType().isEntityType() (true) and field.getType().isAssociationType() (true).
Many-to-one relationship properties can be detected and excluded using field.getType().isEntityType() (true) and field.getType().isAssociationType() (false).
However, I need to get the Java type and field name of the identifier property of the parent entities in the many-to-one relationship, so I can create the foreign identifier property on the DTO.
It seems like it should be possible to get a reference to the parent entity from the pojo field in the Freemarker template, but I so far I haven't found a way. This is the closest I've come:
Code:
<#-- // Fields -->
<#foreach field in pojo.getAllPropertiesIterator()>
<#if field.getType().isAssociationType()>
${field.getValue()}
<#foreach mappingColumn in field.getValue().getColumnIterator()>
${mappingColumn.getQuotedName()}
</#foreach>
</#if>
</#foreach>
field.getValue() returns org.hibernate.mapping.ManyToOne([org.hibernate.mapping.Column(ParentID)])
mappingColumn.getQuotedName() returns ParentID
I could hard code the Java type of the identifier and force the identifier column name to the proper case, but this is not an elegant solution.
I'll keep looking through the Hibernate docs and post here if I find a solution, but any hints would be appreciated.
Oh, and is the Hibernate Tools trunk (rev 18919) still only compatible with Hibernate 3.2? I've looked for the compatibility matrix but the majority of Google's links to the numeric JBoss reference pages are broken...