0

I would like to generate a customized DAO which extends ClassA and implements SampleInterface. The SampleInterface has a method which should be implemented while generating this DAO. And also the naming convention of the DAO's I generate should have DAO at the end in the class name but not "Home", as the hibernate tools generate the DAO Classes with Home at the end by default.

My table Names are Employee, Address, Salary and I have my entity generated and they are in com.mycompany.model package. Currently I have Address, Employee, Salary Entities with all the annotations and mapping in it. I want to generate AddressDAO, EmployeeDAO and SalaryDAO using below reverse engineering strategy.

Below is my Reverse Engineering Strategy class

 public class DAOReverseEngineeringStrategy extends
            DelegatingReverseEngineeringStrategy {

        public DAOReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
            super(delegate);
            // TODO Auto-generated constructor stub
        }

        @Override
        public Map tableToMetaAttributes(final TableIdentifier tableIdentifier) {
            Map<String, MetaAttribute> metaAttributes = super
                    .tableToMetaAttributes(tableIdentifier);
            if (metaAttributes == null) {
                metaAttributes = new HashMap<String, MetaAttribute>();
            }

            MetaAttribute attributeExtends = new MetaAttribute("extends");
            attributeExtends.addValue("ClassA");
            metaAttributes.put("extends", attributeExtends);

            MetaAttribute attributeImpl = new MetaAttribute("implements");
            attributeImpl.addValue("SampleInterface");
            metaAttributes.put("implements", attributeImpl);

            MetaAttribute attributeImport = new MetaAttribute("extra-import");
            attributeImport.addValue("com.mycompany.ClassA");
            attributeImport.addValue("com.mycompany.SampleInterface");
            attributeImport.addValue("com.mycompany.model.*");
            metaAttributes.put("extra-import", attributeImport);

            return metaAttributes;
        }
    }
Bashir
  • 2,057
  • 5
  • 19
  • 44
devvapp
  • 143
  • 1
  • 2
  • 9

2 Answers2

0

Not sure if this is still open, but like to share my answer anyways.

I have not tried it with Reverse Engineering Strategy class, but yes, with the ftl (free marker template) files available under dao/daoHome.ftl.

Vasanth
  • 1
  • 3
0

You can override the free marker template file in hibernate-tools/dao/daohome.ftl lib. After that edit file template pattern as below:

enter image description here

enter image description here

In my example, I have renamed to {ClassName}RepositoryImpl. Reference: http://docs.jboss.org/tools/latest/en/hibernatetools/html_single/index.html#exportes

Giang Phan
  • 534
  • 7
  • 15