I have this XSD definition that I use to generate JPA objects via Hyperjaxb3. Basically, what I need is that the generated class will give me access to the column and not to the entity. I want to be able to modify the CASE_ID field directly and not through the entity
<?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>
This is part of the configuration file 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>
This works perfectly. Howhever, this generates a field like this.
/**
* 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;
}
What I need is a way to modify the hyperjaxb configuration to be able to generate something like this:
@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;
}
Being this @JoinColumn(name = "CASE_ID", updatable = false, insertable = false) the part I can't figure out how to configure in my binding.xjb file so I can define my complex type like this
<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" />
Please try:
<orm:join-column name="CASE_ID" updatable="false" insertable="false"/>
See this schema, it documents the customizations schema for HJ3.
Disclaimer: I am the author of Hyperjaxb3.