hibernatereverse-engineeringtransienthbm2java

hibernate reverse engineering to include a @Transient property


I am trying to include following



private org.springframework.web.multipart.commons.CommonsMultipartFile photo;


    @Transient
    public CommonsMultipartFile getPhoto() {
        return photo;
    }

    public void setPhoto(CommonsMultipartFile photo) {
        this.photo = photo;
    }

in my pojo class generated from database table.

I have studied to find there is a way to mention extra class code in meta tag like following

http://www.scribd.com/doc/23123635/30/Guiding-the-reverse-engineering-process

but this does not allow to add property variable photo.

Please suggest a way how can I do it in reveng.xml so that this code is included on every run of hbm2java.

Thanks in advance!


Solution

  • You can achieve such custom code by using reveng templates. If you open hibernate-tools.jar you will find .ftl files in the pojo folder. You need to override them to put custom code.

    Steps:

    1. If you are using maven then put this under componentProperties for hbm2java goal:

      <templatepath>src/main/resources/reveng.templates/</templatepath>
      <filepattern>*.java</filepattern>
      
    2. Create revenge.templates/pojo folder under resources. Make sure that the folder name is always pojo, otherwise the overrides are not detected.

    3. Create pojo.ftl file and copy the contents from the pojo.ftl file present in the jar. Add all the import statements in this file.

    4. Similarly, follow the other files to find out where exactly you want to put the custom code.