Skip to content

Constructor id arguments don't need to be listed first #2541

Closed

Description

@Condor70

I was working on using MyBatis with pre-existing classes and i ran into the problem that according to the DTD idArgs need to come before args in the constructor.

This following example doesn't validate, although MyBatis doesn't actually have this restriction:

<resultMap id="MyClass" type="test.MyClass">
	<constructor> <!-- Error: The content of element type "constructor" must match "(idArg*,arg*)". -->
		<arg column="name" javaType="string" />
		<idArg column="id" javaType="string" />
	</constructor>
</resultMap>

Can mybatis-3-mapper.dtd be changed from:
<!ELEMENT constructor (idArg*,arg*)>
to
<!ELEMENT constructor ((idArg|arg)*)>

Activity

  1. Condor70 commented on Apr 29, 2022

    @Condor70
    Author

    I just noticed that MyBatis has an XSD as well, which also would need to change:

    Current mybatis-mapper.xsd:

    <xs:element name="constructor">
    	<xs:complexType>
    		<xs:sequence>
    			<xs:element minOccurs="0" maxOccurs="unbounded" ref="idArg"/>
    			<xs:element minOccurs="0" maxOccurs="unbounded" ref="arg"/>
    		</xs:sequence>
    	</xs:complexType>
    </xs:element>
    

    New mybatis-mapper.xsd:

    <xs:element name="constructor">
    	<xs:complexType>
    		<xs:choice minOccurs="0" maxOccurs="unbounded">
    			<xs:element ref="idArg"/>
    			<xs:element ref="arg"/>
    		</xs:choice>
    	</xs:complexType>
    </xs:element>
    
  2. harawata commented on Apr 29, 2022

    @harawata
    Member

    Hello @Condor70 ,

    I didn't know this was possible with DTD.
    Would you send us a PR?
    If you are busy, please just let me know and I'll take care of it later.

    FYI, if you specify name, the order of idArg/arg does not matter.
    See #721

  3. self-assigned this
    on May 14, 2022
  4. added this to the 3.5.10 milestone on May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions