[hibernate-issues] [Hibernate-JIRA] Created: (HBX-1132) POJO java code exporter (<hbm2java>) should generate field or property access Java annotated files

Julien Kronegg (JIRA) noreply at atlassian.com
Tue Aug 18 10:14:19 EDT 2009


 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/tools/src/templates/pojo/PojoFields.ftl
http://anonsvn.jboss.org/repos/hibernate/branches/Branch_3_2/HibernateExt/tools/src/templates/pojo/PojoPropertyAccessors.ftl
            Reporter: Julien Kronegg
            Priority: Minor
         Attachments: 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: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list