问题
The default configuration of hyperjaxb
is creating hibernate annotations that result in hibernate
annotations that produce incredibly verbose SQL
statements that result in SQLException
s at worst and slow performance at best. Specifically, the CascadeType.ALL
setting seems to be the default. How do I override the default settings so that CascadeType
, FetchType
, and other parameters are set on a customized basis? And is it possible to set these default variables on a global level so that I do not have to change every one of many hundreds of references in my schema.xsd file?
Here is an example. Hyperjaxb
is generating the following hibernate
annotation:
@ManyToOne(targetEntity = Code.class, cascade = {
CascadeType.ALL
})
@JoinColumn(name = "SOME_CODE1_P_0")
public Code getSomeCode1() {
return someCode1;
}
from the following schema fragment:
<xs:complexType name="SomeTypeName">
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="someCode1" type="Code" minOccurs="0"/>
<xs:element name="someCode2" type="Code" minOccurs="0"/>
<xs:element name="someCode3" type="Code" minOccurs="0"/>
<xs:element name="someCode4" type="Code" minOccurs="0"/>
<xs:element name="someCode5" type="Code" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Code">
<!--<xs:sequence>elements with nested data types omitted for simplicity</xs:sequence>-->
<xs:attribute name="code" type="xs:string" use="optional"></xs:attribute>
<xs:attribute name="Name" type="xs:string" use="optional"></xs:attribute>
</xs:complexType>
回答1:
You can customize default mappings as you want:
http://confluence.highsource.org/display/HJ3/Customizing+default+mappings
Here are the default customizations.
And here's a test project which customizes defaults.
For instance, customizing the default cascade for many-to-one
would look like (untested):
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<hj:persistence>
<hj:default-many-to-one>
<!-- So what do you think to be a reasonable default mapping? -->
<orm:cascade>
<orm:cascade-persist/>
</orm:cascade>
</hj:default-many-to-one>
</hj:persistence>
</jaxb:bindings>
Further links:
- Customizations schema
- Customizations guide
Please check the documentation. You can (but don't have to) customize a lot.
来源:https://stackoverflow.com/questions/26597201/customizing-hibernate-properties-in-hyperjaxb