0
我想生成一个定制的DAO,它扩展了ClassA并实现了SampleInterface。 SampleInterface有一个在生成这个DAO时应该实现的方法。而且,我生成的DAO的命名约定应该在类名称末尾有DAO,但不包含“Home”,因为hibernate工具默认在末尾生成带有Home的DAO Classes。如何使用休眠工具生成自定义的DAO
我的表名称是员工,地址,工资和我有我的实体生成,他们在com.mycompany.model包。目前,我拥有地址,员工,工资实体以及所有注释和映射。我想使用下面的逆向工程策略生成AddressDAO,EmployeeDAO和SalaryDAO。
下面是我的逆向工程战略类
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;
}
}
谢谢。