免责声明:我是Hyperjaxb3的作者。
实体名称不可自定义,但您可以实施自己的命名策略来生成完全限定的实体名称。
为此,您必须实现org.jvnet.hyperjaxb3.ejb.strategy.naming.Naming
接口。最简单的方法是子类org.jvnet.hyperjaxb3.ejb.strategy.naming.impl.DefaultNaming
化并覆盖该getEntityName
方法:
public String getEntityName(Mapping context, Outline outline, NType type) {
final JType theType = type.toType(outline, Aspect.EXPOSED);
assert theType instanceof JClass;
final JClass theClass = (JClass) theType;
return CodeModelUtils.getPackagedClassName(theClass);
}
您还必须包含org\jvnet\hyperjaxb3\ejb\plugin\custom\applicationContext.xml
资源来配置您的自定义命名策略:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean name="naming" class="com.acme.foo.CustomNaming">
<property name="reservedNames" ref="reservedNames"/>
</bean>
</beans>
最后,全部编译,打包为 JAR 并添加到 HJ3 类路径,例如通过 Maven POM 中的插件依赖项:
<plugin>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<configuration>...</configuration>
<dependencies>
<dependency>
<groupId>com.acme.foo</groupId>
<artifactId>hyperjaxb3-custom-naming-extension</artifactId>
<version>...</version>
</dependency>
</dependencies>
</plugin>
这是一个实现/配置自定义命名策略的测试项目:
也可以看看: