我已经扩展了 org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy
类,用于使用 hibernate 工具库和 ant 脚本进行自定义逆向工程。
运行 ant 脚本后,类将生成为 -
@Entity
@Table(name="account"
,catalog="testdb"
)
public class Account implements java.io.Serializable {
}
在上面的类 catalog
中,名称总是被添加到生成的类中。
我正在尝试使用 CustomReverseEngineeringStrategy.java 类删除目录名称。 这是我的 java 类 -
public class CustomReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {
public Map<String, MetaAttribute> tableToMetaAttributes(TableIdentifier tableIdentifier){
Map<String, MetaAttribute> metaAttributes = super.tableToMetaAttributes(tableIdentifier);
if (metaAttributes == null) {
metaAttributes = new HashMap<String, MetaAttribute>();
}
String catalogName = tableIdentifier.getCatalog();
if(metaAttributes.containsKey(catalogName)){
System.out.print(catalogName);
metaAttributes.remove(catalogName);
}
return metaAttributes;
}
}
在此表中,标识符返回目录名称。但是,没有设置目录名称的方法。 metaAttributes 也不包含目录名称的键。
我想使用 CustomReverseEngineeringStrategy 类在类生成过程中删除此目录名称。你能帮我吗?
最佳答案
我使用 maven-replacer-plugin 解决了这个问题。
也许这不是您要问的,但它确实有效。
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>(version)</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<regex>false</regex>
<token>,catalog="testdb"</token>
<value></value>
</configuration>
</plugin>
关于java - Hibernate 逆向工程使用 CustomReverseEngineeringStrategy 类删除目录名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8396765/