OK, I've figured out how to do this in MyEclipse.
There are two facilities:
- templates are used to control the code generated for the various java and hbm.xml files.
- DelegatingReverseEngineeringStrategy is a java class used to define a lot of the mapping of various DB names and properties to the ones to be used in the java classes.
For my task, to remove the "R_" prefix from the DB tables, I needed to us the second one.
You might think there would be one method to define this, but there are different methods for the different places where the table/class name is used - in the class name definition, as fiels types, as parameter types, etc.
Here is the actual class I created. Works ok for my situation, but you might find you need to implement some of the other methods:
Code:
import java.util.List;
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;
import org.hibernate.mapping.ForeignKey;
public class RevEngStrategy extends DelegatingReverseEngineeringStrategy {
public RevEngStrategy(ReverseEngineeringStrategy strategy) {
super(strategy);
}
@Override
public String foreignKeyToCollectionName(String keyname,
TableIdentifier fromTable, List fromColumns,
TableIdentifier referencedTable, List referencedColumns,
boolean uniqueReference) {
fromTable = removePrefix(fromTable);
referencedTable = removePrefix(referencedTable);
return super.foreignKeyToCollectionName(keyname, fromTable, fromColumns,
referencedTable, referencedColumns, uniqueReference);
}
@Override
public String foreignKeyToEntityName(String keyname,
TableIdentifier fromTable, List fromColumnNames,
TableIdentifier referencedTable, List referencedColumnNames,
boolean uniqueReference) {
fromTable = removePrefix(fromTable);
referencedTable = removePrefix(referencedTable);
return super.foreignKeyToEntityName(keyname, fromTable, fromColumnNames,
referencedTable, referencedColumnNames, uniqueReference);
}
@Override
public String foreignKeyToManyToManyName(ForeignKey fromKey,
TableIdentifier middleTable, ForeignKey toKey,
boolean uniqueReference) {
middleTable = removePrefix(middleTable);
// TODO Auto-generated method stub
return super.foreignKeyToManyToManyName(fromKey, middleTable, toKey,
uniqueReference);
}
@Override
public String tableToCompositeIdName(TableIdentifier identifier) {
identifier = removePrefix(identifier);
return super.tableToCompositeIdName(identifier);
}
@Override
public String tableToIdentifierPropertyName(TableIdentifier tableIdentifier) {
tableIdentifier = removePrefix(tableIdentifier);
return super.tableToIdentifierPropertyName(tableIdentifier);
}
@Override
public String tableToClassName(TableIdentifier tableIdentifier) {
tableIdentifier = removePrefix(tableIdentifier);
return super.tableToClassName(tableIdentifier);
}
private TableIdentifier removePrefix(TableIdentifier tableIdentifier) {
String name = tableIdentifier.getName();
if (name.toUpperCase().startsWith("R_")) {
tableIdentifier = new TableIdentifier(tableIdentifier.getSchema(), tableIdentifier.getCatalog(), name.substring(2));
}
return tableIdentifier;
}
}