max wrote:
Dude, it's christmas - don't expect answers immediately ;)
Use a custom ReverseEngineeringStrategy which implements tableToClassName which cuts of the first "t_"
There you go, and Merry Christmas ;)
hehehe, sorry for being so eager :)
I actually fixed it yesterday and thought I'd explain how, but you were faster than me. I used the following resources I found by Googling:
Here's how I did:
1. I packed a single class named foo.bar.MyReverseEngineeringStrategy (code below) in a jar file named MyReverseEngineeringStrategy.jar
2. I put the jar in <jboss-seam-root>\lib
3. I edited the file <jboss-seam-root>\lib\seam-gen\build.xml in two places:
3a. First add the jar:
<target name="init-generate">
<path id="htools.classpath">
<pathelement path="${seam.dir}/lib/gen/jboss-seam-gen.jar"/>
...
<pathelement path="${seam.dir}/lib/MyReverseEngineeringStrategy.jar"/>
3b. Then add my custom reversestrategy class:
<jdbcconfiguration propertyfile="${seam-gen.properties}"
packagename="${model.package}"
revengfile="${project.home}/resources/seam-gen.reveng.xml"
reversestrategy="foo.bar.MyReverseEngineeringStrategy"
4. Then I ran seam generate
Works like a charm! I do not need to change anything in reveng.xml using this strategy.
Here's the code. I have not tried to make it fancy in any way, just do the work. The code is not performance critical as it's used very seldom anyway.
Code:
package foo.bar;
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 MyReverseEngineeringStrategy extends
DelegatingReverseEngineeringStrategy {
public MyReverseEngineeringStrategy(
ReverseEngineeringStrategy delegate) {
super(delegate);
}
public String foreignKeyToManyToManyName(ForeignKey fromKey,
TableIdentifier middleTable, ForeignKey toKey,
boolean uniqueReference) {
String defaultName = super.foreignKeyToManyToManyName(fromKey,
middleTable, toKey, uniqueReference);
String firstChar = defaultName.toLowerCase().substring(0, 1);
return firstChar + defaultName.substring(1);
}
@SuppressWarnings("unchecked")
public String foreignKeyToEntityName(String keyname,
TableIdentifier fromTable, List fromColumnNames,
TableIdentifier referencedTable, List referencedColumnNames,
boolean uniqueReference) {
String defaultName = (String) super.foreignKeyToEntityName(keyname,
fromTable, fromColumnNames, referencedTable,
referencedColumnNames, uniqueReference);
String firstChar = defaultName.toLowerCase().substring(0, 1);
return firstChar + defaultName.substring(1);
}
@SuppressWarnings("unchecked")
public String foreignKeyToCollectionName(String keyname,
TableIdentifier fromTable, List fromColumns,
TableIdentifier referencedTable, List referencedColumns,
boolean uniqueReference) {
String defaultName = super.foreignKeyToCollectionName(keyname,
fromTable, fromColumns, referencedTable, referencedColumns,
uniqueReference);
String firstChar = defaultName.toLowerCase().substring(0, 1);
return firstChar + defaultName.substring(1);
}
public String tableToClassName(TableIdentifier tableIdentifier) {
String defaultName = super.tableToClassName(tableIdentifier);
String tableName = tableIdentifier.getName();
if (tableName.startsWith("t_")) {
int idx = defaultName.lastIndexOf(".");
String className = defaultName.substring(idx + 2);
String packageName = defaultName.substring(0, (idx + 1));
return packageName + className;
}
return defaultName;
}
}
Thanks for the reply, and a Happy New Year :)