]
Max Rydahl Andersen commented on HBX-1132:
------------------------------------------
why do you have two different sets of ftl's ? couldn't you just do conditonal
include on field or properties ?
Could you create a patch for this then this would be much easier to look into and possibly
apply ?
POJO java code exporter (<hbm2java>) should generate field or
property access Java annotated files
---------------------------------------------------------------------------------------------------
Key: HBX-1132
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-1132
Project: Hibernate Tools
Issue Type: New Feature
Components: hbm2java
Affects Versions: 3.2.4 Beta1
Environment:
http://anonsvn.jboss.org/repos/hibernate/branches/Branch_3_2/HibernateExt...
http://anonsvn.jboss.org/repos/hibernate/branches/Branch_3_2/HibernateExt...
Reporter: Julien Kronegg
Priority: Minor
Attachments: Ejb3FieldGetAnnotation.ftl, GetFieldAnnotation.ftl, PojoFields.ftl,
PojoPropertyAccessors.ftl
Currently, the POJO java code exporter generates only property access mode Java files,
i.e. the JPA annotations are put on the getters only.
This is done in PojoFields.ftl (which does not contain annotations on fields) and in
PojoPropertyAccessors.ftl (which includes the GetPropertyAnnotation.ftl that produces
annotations on the methods).
It would be nice if the hbm2java task generate also field or property access mode
entities (with property access mode by default).
The implementation could be based on the following workaround.
Workaround:
------------------
1) extract the following files from the hibernate-tools.jar/ and put them in the /pojo/
directory:
PojoFields.ftl
PojoPropertyAccessors.ftl
GetPropertyAnnotation.ftl
Ejb3PropertyGetAnnotation.ftl
2) rename GetPropertyAnnotation.ftl to GetFieldAnnotation.ftl and change references from
"property" to "field", resulting in the attached file
GetFieldAnnotation.ftl
3) rename Ejb3PropertyGetAnnotation.ftl to Ejb3FieldGetAnnotation.ftl and change
references from "property" to "field", resulting in the attached file
Ejb3FieldGetAnnotation.ftl
4) edit PojoFields.ftl to add a conditional inclusion of GetFieldAnnotation.ftl
(resulting in the attached PojoFields.ftl):
- </#if> ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)}
${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> =
${pojo.getFieldInitialization(field, jdk5)}</#if>;
+ </#if>
+ <#if exporter.properties.containsKey('jpaAccessMode') &&
jpaAccessMode.equals('field')>
+ <#include "GetFieldAnnotation.ftl"/>
+ </#if>
+ ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)}
${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> =
${pojo.getFieldInitialization(field, jdk5)}</#if>;
5) edit the PojoPropertyAccessors.ftl to change to a conditional inclusion of
GetPropertyAnnotation.ftl (resulting in the attached PojoPropertyAccessors.ftl):
- <#include "GetPropertyAnnotation.ftl"/>
+ <#if !exporter.properties.containsKey('jpaAccessMode') ||
!jpaAccessMode.equals('field')>
+ <#include "GetPropertyAnnotation.ftl"/>
+ </#if>
6) in the Ant build.xml, add a property <property name="jpaAccessMode"
value="field"/> to the <hibernate> tag, for example:
<hibernate ...>
<jdbcconfiguration .../>
<property name="jpaAccessMode" value="field"/><!--
possible values are : field | property ; any other value defaults to property -->
<hbm2java ...>
</hibernate>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: