![](/img/trans.png)
[英]Hyperjaxb3: Is it possible to avoid Items table/class creation on PO sample?
[英]hyperjaxb3 add extra columns (ie creation timestamp)
我正在嘗試使用綁定文件添加一個額外的列,該綁定文件用於從xsd(很大)獲得的模型。 添加的字段需要保留,但不能序列化。
我嘗試了hj:generated-property
但是它沒有任何作用。
為了給出到目前為止我嘗試過的示例,我使用git來源的PO Sample在標簽0.6.0 ejb / tests / po-customized上進行了測試,並將其添加到綁定中...
綁定文件
...
<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>
...
運行mvn clean test
, PurchaseOrderType沒有新字段。 測試運行沒有錯誤。
是否可以添加這樣的字段?
不可能。 hj:generated-property
用於自定義生成屬性,而不是生成新屬性。
考慮使用諸如Code Injector插件之類的東西,或者為生成的類指定一個超類。 超類將具有其他字段。
披露:我是Hyperjaxb3的作者。
實施代碼注入器解決方案以按照@lexicore的建議進行解析(謝謝!)
我需要在兩個文件中進行如下更改:
綁定文件
...
<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
作為注入的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.