Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Condor70 opened this issue Apr 29, 2022 · 2 comments · Fixed by #2548
Closed

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

Condor70 opened this issue Apr 29, 2022 · 2 comments · Fixed by #2548
Assignees
Labels
enhancement Improve a feature or add a new feature
Milestone

Comments

@Condor70
Copy link

Condor70 commented Apr 29, 2022

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)*)>

@Condor70
Copy link
Author

Condor70 commented Apr 29, 2022

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>

@harawata
Copy link
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

Condor70 pushed a commit to Condor70/mybatis-3 that referenced this issue May 5, 2022
@harawata harawata self-assigned this May 14, 2022
@harawata harawata added the enhancement Improve a feature or add a new feature label May 14, 2022
@harawata harawata added this to the 3.5.10 milestone May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants