Here is what did so far:
1. create two new files under pojo:
Ejb3FieldGetAnnotation.ftl
Code:
<#if ejb3>
<#if pojo.hasIdentifierProperty()>
<#if field.equals(clazz.identifierField)>
${pojo.generateAnnIdGenerator()}
<#-- if this is the id field -->
<#-- explicitly set the column name for this field-->
</#if>
</#if>
<#if c2h.isManyToOne(field)>
<#--TODO support @OneToOne true and false-->
${pojo.generateManyToOneAnnotation(field)}
<#--TODO support optional and targetEntity-->
${pojo.generateJoinColumnsAnnotation(field, cfg)}
<#elseif c2h.isCollection(field)>
${pojo.generateCollectionAnnotation(field, cfg)}
<#else>
${pojo.generateBasicAnnotation(field)}
${pojo.generateAnnColumnAnnotation(field)}
</#if>
</#if>
GetFieldAnnotation.ftlCode:
<#include "Ejb3FieldGetAnnotation.ftl"/>
2. modified
PojoFields.ftl to include ejb ennotation.
Code:
<#-- // Fields -->
<#foreach field in pojo.getAllPropertiesIterator()><#if pojo.getMetaAttribAsBool(field, "gen-property", true)> <#if pojo.hasMetaAttribute(field, "field-description")> /**
${pojo.getFieldJavaDoc(field, 0)}
*/
</#if>
<#include "GetFieldAnnotation.ftl"/>
${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
</#if>
</#foreach>
3. modified
PojoPropertyAccessors.ftl to get rid of ejb3 annotation.
Code:
<#-- // Property accessors -->
<#foreach property in pojo.getAllPropertiesIterator()>
<#if pojo.getMetaAttribAsBool(property, "gen-property", true)>
<#if pojo.hasFieldJavaDoc(property)>
/**
* ${pojo.getFieldJavaDoc(property, 4)}
*/
</#if>
${pojo.getPropertyGetModifiers(property)} ${pojo.getJavaTypeName(property, jdk5)} ${pojo.getGetterSignature(property)}() {
return this.${property.name};
}
${pojo.getPropertySetModifiers(property)} void set${pojo.getPropertyName(property)}(${pojo.getJavaTypeName(property, jdk5)} ${property.name}) {
this.${property.name} = ${property.name};
}
</#if>
</#foreach>
So far it works except missing annotations for identity ID field, the reason seems to be field.equals(clazz.identifierField) returns false. What is the correct expression to check if a field is ientifier field?