users@jaxb.java.net

Re: Hyperjaxb3 association customization

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 21 Jan 2010 11:49:42 +0100

Hi Steffen,

>> I'm stuck trying to customize a one-to-many association. I'd like to reduce
>> the cascadetype from 'all' to just all-'delete'. I'm using maven with the
>> hyperjaxb3 plugin, version 0.5.4.
>>
>>
>> Schema snippet:
>> ...
>> <xs:complexType name="Category">
>> <xs:choice maxOccurs="unbounded">
>> <xs:element name="element1" type="...">
>> <xs:element name="element2" type="...">
>> <xs:element name="element3" type="...">
>> </xs:choice>
>> </xs:complexType>
>> ...
>>
>> My external customization is:
>> ...
>> <jxb:bindings node="//xs:complexType[@name='Category']/xs:choice">
>> <hj:one-to-many>
>> <orm:join-column />
>> <orm:cascade>
>> <orm:cascade-persist />
>> <orm:cascade-refresh />
>> <orm:cascade-merge />
>> </orm:cascade>
>> </hj:one-to-many>
>> </jxb:bindings>
>> ...
>>
>> All I'm getting is this error message: "com.sun.istack.SAXParseException2:
>> compiler was unable to honor this hj:one-to-many customization. It is
>> attached to a wrong place, or its inconsistent with other bindings."
>>
>> Could anybody please point to my hopefully blatant error?
>
> The problem is in xs:choice/_at_maxOccurs="unbounded". This produces a
> heterogeneous list and HJ3 must create additional classes to wrap this
> construct. When creating these classes, customizations are apparently
> not propagated. I'd say it is a missing feature.

I've made a prototypic implementation in the current 0.5.5-SNAPSHOT.
Here's how it looks with customization:

        <xsd:complexType name="issueHJIII26Type">
                <xsd:choice maxOccurs="unbounded">
                        <xsd:annotation>
                                <xsd:appinfo>
                                        <hj:generated-property propertyName="Ot">
                                                <hj:one-to-many>
                                                        <orm:join-column />
                                                        <orm:cascade>
                                                                <orm:cascade-persist/>
                                                                <orm:cascade-refresh/>
                                                                <orm:cascade-merge/>
                                                        </orm:cascade>
                                                </hj:one-to-many>
                                        </hj:generated-property>
                                </xsd:appinfo>
                        </xsd:annotation>
                        <xsd:element name="one" type="test:issueHJIII26OneType"/>
                        <xsd:element name="two" type="test:issueHJIII26TwoType"/>
                </xsd:choice>
        </xsd:complexType>

        <xsd:complexType name="issueHJIII26OneType">
                <xsd:attribute name="one" type="xsd:boolean"/>
        </xsd:complexType>

        <xsd:complexType name="issueHJIII26TwoType">
                <xsd:attribute name="two" type="xsd:boolean"/>
        </xsd:complexType>

The hj:generated-property customization element provides HJ3 with
instruction, how new "artificial" property must be generated.
@propertyName gives the name of the new property. Contents are used as
customizations. Here's what this generates:

    @OneToMany(targetEntity = IssueHJIII26TypeOneOrTwoItem.class, cascade = {
        CascadeType.PERSIST,
        CascadeType.ALL,
        CascadeType.REFRESH,
        CascadeType.MERGE
    })
    @JoinColumn(name = "OT_ISSUEHJIII26TYPE_HJID")
    public List<IssueHJIII26TypeOneOrTwoItem> getOt();

I've commited the changes to SVN, if you wish you can checkout, build
and test if your scenario is now covered.

These new hj:generated-class and hj:generated-property customizations
are new, at the moment they're implemented prototypically and might be
changed.
Let me know if you like them as they are, or if anything must be
changed. I'd like to release these features with 0.5.5.
I'll be grateful for your feedback.

Bye.
/lexi