我有这个 XSD 定义,用于通过 Hyperjaxb3 生成 JPA 对象。基本上,我需要的是生成的类将允许我访问列而不是实体。我希望能够直接修改CASE_ID字段,而不是通过实体
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ws="http://www.sample.code/types"
targetNamespace="http://www.sample.code/types"
elementFormDefault="qualified">
<xsd:complexType name="CaseType">
<xsd:annotation>
<xsd:documentation>
Entity 1
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id" type="xsd:integer" />
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="priority" type="xsd:boolean"/>
<xsd:element name="elements" type="ws:ElementType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Case" type="ws:CaseType" />
<xsd:complexType name="ElementType">
<xsd:annotation>
<xsd:documentation>
Entity 2
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id" type="xsd:integer" />
<xsd:element name="creation_date" type="xsd:dateTime"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="element_type" type="xsd:string"/>
<xsd:element name="case" type="ws:CaseType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Element" type="ws:ElementType" />
</xsd:schema>
这是配置文件binding.xjb的一部分
<bindings node="xsd:complexType[@name='CaseType']">
<bindings node=".//xsd:element[@name='id']">
<hj:id>
<orm:generated-value strategy="AUTO"/>
</hj:id>
</bindings>
<bindings node=".//xsd:element[@name='elements']">
<hj:one-to-many>
<orm:join-column name="CASE_ID"/>
</hj:one-to-many>
</bindings>
</bindings>
<bindings node="xsd:complexType[@name='ElementType']">
<bindings node=".//xsd:element[@name='case']">
<hj:many-to-one>
<orm:join-column name="CASE_ID"/>
</hj:many-to-one>
</bindings>
<bindings node=".//xsd:element[@name='id']">
<hj:id>
<orm:generated-value strategy="AUTO"/>
</hj:id>
</bindings>
</bindings>
这完美地工作。但是,这会生成这样的字段。
/**
* Obtient la valeur de la propriété case.
*
* @return
* possible object is
* {@link CaseType }
*
*/
@ManyToOne(targetEntity = CaseType.class, cascade = {
CascadeType.ALL
})
@JoinColumn(name = "CASE_ID")
public CaseType getCase() {
return _case;
}
/**
* Définit la valeur de la propriété case.
*
* @param value
* allowed object is
* {@link CaseType }
*
*/
public void setCase(CaseType value) {
this._case = value;
}
我需要的是一种修改 hyperjaxb 配置的方法,以便能够生成如下内容:
@ManyToOne(targetEntity = CriminalCaseType.class, cascade = {
CascadeType.ALL
})
@JoinColumn(name = "CASE_ID", updatable = false, insertable = false)
public CriminalCaseType getCase() {
return _case;
}
.
.
.
@Basic
@Column(name = "CASE_ID")
public BigInteger getCaseId() {
return _caseId;
}
public BigInteger setCaseId(BigInteger value) {
this._caseId = value;
}
作为这个@JoinColumn(name = "CASE_ID", updatable = false, insertable = false)我无法弄清楚如何在我的binding.xjb文件中进行配置,所以我可以像这样定义我的复杂类型
<xsd:complexType name="ElementType">
<xsd:annotation>
<xsd:documentation>
Entity 2
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id" type="xsd:integer" />
<xsd:element name="case_id" type="xsd:integer" />
<xsd:element name="creation_date" type="xsd:dateTime"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="element_type" type="xsd:string"/>
<xsd:element name="case" type="ws:CaseType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Element" type="ws:ElementType" />