1

我已经从 hyperjax3 生成了 .java 类,这些类已经用@Entity 和 @Table等注释进行了注释。”

在@Entity 中,类名自动添加如下: @Entity(name = "MyClassName") 但是我希望这个名称字段具有完全限定的类名 ,因为
@Entity(name = "myPackage.here.MyClassName") 我正在使用 hyperjaxb3-ejb-samples-po-initial-0.5.6示例并生成带注释的 java 类通过运行mvn clean install我的 XSD 模式存在src\main\resources于 maven 项目的文件夹中。

*我已经搜索并找到了一种使用 auto-import=false的方式,但我无法将其合并,因为我只是在运行该 maven 项目。

4

1 回答 1

1

免责声明:我是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>

这是一个实现/配置自定义命名策略的测试项目:

也可以看看:

于 2015-12-04T20:00:02.470 回答