hyperjaxb3 添加额外的列(即创建时间戳)

hyperjaxb3 add extra columns (ie creation timestamp)

我正在尝试添加一个额外的列,使用绑定文件到从 xsd(一个大的)获得的模型。添加的字段需要持久化,但不能序列化

我试过 hj:generated-property 但它没有任何作用。

为了给出我到目前为止所尝试的示例,我在标签 0.6.0 ejb/tests/po-customized 上使用 PO Sample from git sources 进行了测试,并将其添加到绑定中...

bindings.xjb

...
        <jaxb:bindings node="xs:complexType[@name='PurchaseOrderType']">
            <hj:entity>
                <orm:table name="po"/>
                <!-- adding creation timeStamp -->
                <hj:generated-property name="creationTimestamp" propertyName="creationTimestamp" propertyQName="creationTimestamp"
                    propertyKind="xs:dateTime" />
            </hj:entity>
        </jaxb:bindings>
...

当 运行ning mvn clean test 时,PurchaseOrderType 没有新字段。测试 运行 没有错误。

是否可以添加这样的字段?

不可能。 hj:generated-property用于自定义生成属性,不生成新属性。

考虑使用类似 Code Injector 的插件,或者为您生成的 类 指定一个超类。超类会有额外的字段。

披露:我是 Hyperjaxb3 的作者。

按照@lexicore 的建议实施Code Injector solution 解决(谢谢!)

我需要对两个文件进行如下更改:

bindings.xjb

...
        <jaxb:bindings node="xs:complexType[@name='PurchaseOrderType']">
            <hj:entity>
                <orm:table name="po"/>
                <!-- REMOVED! hj:generated-property -->
            </hj:entity>
            <ci:code>
// Added for DB only, avoid XML serialization
@XmlTransient
protected Calendar creationTimestamp;

@Basic
@Column(name = "CREATION_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
public Calendar getCreationTimestamp() { return this.creationTimestamp; }

public void setCreationTimestamp(Calendar creationTimestamp) { this.creationTimestamp = creationTimestamp; }
            </ci:code>
        </jaxb:bindings>
...

pom.xml

maven-jaxb21-plugin配置中添加arg

...
<arg>-Xinject-code</arg>
...

考虑到,在添加的代码中,有一些 类 引用了导入的包,如果它们没有导入,您需要在注入的代码中放入完全限定名称。无法将 import 添加为注入代码。