hibernate - Hyperjaxb3: Create lookup table from enumeration element -
i have xsd file includes element enumeration constraint:
<xs:complextype name="request"> <xs:sequence> <xs:element name="commsaddress" type="xs:string" /> <xs:element name="commsaddresstype"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:enumeration value="email"/> <xs:enumeration value="phone"/> </xs:restriction> </xs:simpletype> </xs:element> ...
i commsaddresstype
field in generated java class generated enum values email
, phone
. in turn, hibernate automatically generate database schema commsaddresstype
table containing 2 rows values email
, phone
. request
table can reference these commsaddresstypeid
column.
currently, hyperjaxb3 generates request
class commsaddresstype
field of type string
:
@xmlelement(name="commsaddresstype") protected string commsaddresstype
and schema generated request
table has commsaddresstype
column of type varchar
. result in lot of unnecessary duplicated data.
is there way of achieving described above? also, exposing xsd customer, avoid including jaxb or hyperjaxb tags in schema if possible.
disclaimer: i'm author of hyperjaxb.
if make enumerated types become enums in java, hyperjaxb handle them enums, not strings. can, instance, customize simple type with:
<jaxb:typesafeenumclass/>
see example.
hyperjaxb map corrsponding properties @enumerated
.
no, can't generate lookup table can customize how enum mapped in database. instance, can make mapped enumtype.ordinal
:
<hj:basic><orm:enumerated>ordinal</orm:enumerated></hj:basic>
actually, enums don't need lookup tables jpa. jpa map enums correctly according speified enumtype
mapping.
but may need lookup table own purposes - being able produce human-readable values in joined queries.
in case i'd recommend mapping enum ordinal
, adding lookup table plus corresponding foreign keys on own ddl scripts.
and yes, can of described customizations in separate bindings file (normally bindings.xjb
), don't have directly in schema. see test projects here, there plenty of examples. *.xjb
files in src/main/resources
directories.
Comments
Post a Comment